How to detect Remote notification in didFinishLaunchingWithOption application method in objective c?

后端 未结 4 1471
予麋鹿
予麋鹿 2021-01-28 22:34

when app in not in background mode ,inactive mode and app is completely closed. than how to detect is their any notification using application\'s delegate \"didFinishLaunchingWi

4条回答
  •  感情败类
    2021-01-28 23:11

    Below methods is used for notifiaction

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
     UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
       if (notification)
       {
    
    
       }
    }
    
    
     -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
        NSString *token = [[[[deviceToken description]
                          stringByReplacingOccurrencesOfString:@"<"withString:@""]
                         stringByReplacingOccurrencesOfString:@">" withString:@""]
                        stringByReplacingOccurrencesOfString: @" " withString: @""];
        NSLog(@"Token:%@",token);
    
    }
    
    //app is forground this method will access
     -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {
    
    }
    //need to on teh background fetch option in info plist
    //app is background state this below mthod will call while notification receives
    -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
     {
      NSLog(@"Background mode working%@",userInfo);
    
      if([userInfo[@"aps"][@"content-available"] intValue]== 1) //it's the silent notification when recive preferences and text messages
      {
      }
     }
    
    //handling interactive notification
       - (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forLocalNotification:(nonnull UILocalNotification *)notification completionHandler:(nonnull void (^)())completionHandler {
      }
    

提交回复
热议问题