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メソッドでこれを行うことができます

 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 に答える
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 に答える