1
votes
(void)application:(UIApplication *)application
     didReceiveRemoteNotification:(NSDictionary *)userInfo ;

and

 - (void)application:(UIApplication *)application didReceiveRemoteNotification:
                    (NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult 
                     result))completionHandler{};

never get called ,although i receive the notification on the iphone, Is there any other function that needs to be added for this to work?.Thank you.

Update I tried this when the app is not in background nor active but i didnt receive the message. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Set app's client ID for |GPPSignIn| and |GPPShare|.

[[UIApplication sharedApplication]
 registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

// Clear application badge when app launches
application.applicationIconBadgeNumber = 0;
if ([[launchOptions allKeys] containsObject:UIApplicationLaunchOptionsRemoteNotificationKey]) {

    id userInfo=[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"MESSAGE" message:userInfo delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil];
    [alert show];
}
1
This method call when application is active or backgroud,if you application close then this method never call.nitin kachhadiya
so is there any function that i can implement to receive push notification if the app is not in background nor active?Iman
yes,in didFinishLaunchingWithOptions..nitin kachhadiya
Please make sure, Is your application in the background or foreground? If it's in the foreground, I'm sure that method is called. If it isn't, maybe you aren't putting that method in your application delegate.Ramdhas

1 Answers

2
votes

if your application close and get notification .....

add below code in didFinishLaunchingWithOptions

if ([[launchOptions allKeys] containsObject:UIApplicationLaunchOptionsRemoteNotificationKey]) 
{    
    id userInfo=[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    NSLog(@"%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]);
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"MESSAGE" message:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil];
    [alert show];
}

but this call when you click on notification