Kex
Kex

Reputation: 8619

Receiving a Parse notification and opening the app via the app Icon to view it not the notification

when I receive a notification I use this code in AppDelegate.m

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
   [PFPush handlePush:userInfo];
}

So if the app is opened and currently on screen the notification will be displayed or if the application is in the background tapping on the notification will open the app and display it. Is there a way to tap on the app icon and then display the notification? For example, maybe the user sees the notification come through and wants to view it and clicks on the app icon on the home screen. Is there a way to implement this?

Upvotes: 0

Views: 152

Answers (1)

soulshined
soulshined

Reputation: 10612

Clicking on the app icon won't display anything related to the notification, it will simply load your application per normal use.

However you can set notifications to active tasks once responding to a payload as you stated in your question. Say you send a push notification of a sale going on and they tap on the notification itself you can register tasks to activate upon selection :

Per Parse Docs :

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
. . .
// Extract the notification data
NSDictionary *notificationPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];

// Create a pointer to the Photo object
NSString *photoId = [notificationPayload objectForKey:@"p"];
PFObject *targetPhoto = [PFObject objectWithoutDataWithClassName:@"Photo"
                                                      objectId:photoId];

 // Fetch photo object
 [targetPhoto fetchIfNeededInBackgroundWithBlock:^(PFObject *object, NSError *error) {
    // Show photo view controller
    if (!error && [PFUser currentUser]) {
    PhotoVC *viewController = [[PhotoVC alloc] initWithPhoto:object];
    [self.navController pushViewController:viewController animated:YES];
    }
  }];
}

Alternatively, what you can do is have a dedicated 'Notifications' or 'Messages' HUB or View Controller that has a list of recent notifications for them to reference or select

Upvotes: 1

Related Questions