0

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

谢谢

4

4 回答 4

1

以下方法用于通知

- (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 {
  }
于 2016-06-24T07:30:35.550 回答
0

您可以通过以下方式获取通知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");
   }
}

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

于 2016-06-24T06:52:49.670 回答
0

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

 let launchedFromRemoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] != nil
于 2016-06-24T06:44:06.013 回答
0

如果应用程序已终止并重新启动,则只有在应用程序正在启动时才能检测到远程通知,因为用户在通知托盘中点击了远程通知。

您可以在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
   }
}
于 2016-06-24T07:02:05.947 回答