6

プッシュ通知機能が重要な機能の 1 つであるプロジェクトを行っています。
アプリにいるときは正常に動作しています。通知を受け取り、その通知を処理します。

しかし、問題は、バックグラウンドで通知を受け取ると、アプリのアイコンにバッジが表示され、アイコンをクリックするとアプリが起動しますが、didReceiveRemoteNotificationメソッドが呼び出されないため、その通知を処理できないことです。

また、別の問題として、通知メッセージが表示される場合と表示されdevice notification listない場合があります。

通知リスト項目をクリックしてアプリに入ると、didReceiveRemoteNotification呼び出しが行われ、通知を正常に処理できます。私は次のコードを書きますdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions method

NSDictionary* remoteNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotif != nil)
{
    NSLog(@"didFinishLaunchingWithOptions\nNotification recieved:\n%@",remoteNotif);

    notificationData=[[NSDictionary alloc]initWithDictionary:remoteNotif];
    [notif saveNotification:remoteNotif];
}

これを解決するのを手伝ってください。前もって感謝します。

4

3 に答える 3

2

didfinishlaunchメソッドで行っていることは、 didReceiveRemoteNotificationでも行います。バックグラウンドから来る場合、didfinishlaunchは呼び出されません。

- (void)application:(UIApplication*)application didReceiveRemoteNotification: 
(NSDictionary*)userInfo
{
         UIApplicationState state = [application applicationState];
         if (state == UIApplicationStateActive)
         { 
              //What you want to do when your app was active and it got push notification
         }
         else if (state == UIApplicationStateInactive) 
         {
              //What you want to do when your app was in background and it got push notification
         }
}
于 2013-08-06T10:14:28.850 に答える
0

私は自分のアプリケーションの1つで同じことをしました。アプリのアイコンをクリックしたときに通知を処理する方法はありません。そのため、サーバー呼び出しを行って latestPushNotificationIdSync を取得することができます。サーバーのどこかにデータを保存する必要があるため、サーバーで最新の latestPushNotificationId を確認する必要があります。

   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
     notificationContentDict = launchOptions;
      if([[launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"]count]>0){
            application.applicationIconBadgeNumber = 0;
            NSString *key = [[launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"] valueForKey:@"id"];

            contentId = key;

////// you can use this content id ///// write your code here as per the requirement ..////

    //// display your content on UI /// either get from server or local ...///
        [self displayContent:[launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"] application:application];

        }
       else
        [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
        return YES;
    }


    - (void)applicationDidBecomeActive:(UIApplication *)application
    {

        NSLog(@"badge count ..%d",  application.applicationIconBadgeNumber);

        if( application.applicationIconBadgeNumber >0){
            if(!notificationContentDict){

    make a server call to get "latestPushNotificationIdSync"


            application.applicationIconBadgeNumber = 0;
          NSLog(@"badge count applicationDidBecomeActive.%d",  application.applicationIconBadgeNumber);

        }

        }
    }
于 2013-08-06T10:22:01.997 に答える