如何检测objective c中didFinishLaunchingWithOption应用程序方法中的远程通知?

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

当应用程序不处于后台模式时,非活动模式和应用程序完全关闭。而不是如何使用应用程序的委托 "didFinishLaunchingWithOption" 方法检测他们的任何通知。我已经搜索了很多关于它但没有得到任何东西。请帮助。

谢谢

您可以在 didFinishLaunchingWithOption 方法中执行此操作

 let launchedFromRemoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] != nil

您可以通过以下方式在 didFinishLaunchingWithOption 中获取通知:

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

  NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
     if (notification) {
          NSLog(@"app recieved notification from remote%@",notification);
   }else{
        NSLog(@"app did not recieve notification");
   }
}

试试这个可能对你有帮助。

如果应用程序被终止并再次启动,您可以检测到远程通知 仅当应用程序正在启动时因为用户点击了遥控器通知托盘中的通知。

可以在didFinishLaunchingWithOptions方法中检测到

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

  NSDictionary *notificationDict = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
     if (notificationDict) {
        //Your App received a remote notification
   }else{
        //Your App did not receive a remote notification
   }
}

以下方法用于通知

- (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 {
  }