Pergunta

(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];
}
Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top