在我没有点击ios中的通知之前,没有在后台模式中调用didReceiveRemoteNotification

时间:2014-07-25 04:12:31

标签: ios iphone push-notification

我已经搜索了几个小时,但某处说的是,

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandlerNotification
无论应用程序处于活动状态还是非活动状态,都会调用

。在某个地方,它表示当应用程序处于非活动状态时,推送通知会调用您的didFinishLaunchingWithOptions,您可以在那里检测到这样的通知:

NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]`

在我的情况下,如果用户点击通知并且一切正常,两者都有效,但是当用户没有点击通知并从其图标直接打开应用时会出现问题,那么didFinishLaunchingWithOptions都没有检测到它有通知也didReceiveRemoteNotification被叫。我需要将数据保存在数据库中,从推送通知接收,但是没有点击通知如何调用方法?

1 个答案:

答案 0 :(得分:0)

didFinishLaunchingWithOptions中获取通知数据执行此代码

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

if(launchOptions != nil)
    {
        NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];

        if(remoteNotif != nil){

            [UIApplication sharedApplication].applicationIconBadgeNumber = [[[remoteNotif objectForKey:@"aps"] objectForKey: @"badge"] integerValue];

            //do something here to process notification



        }
    }
}