【问题标题】:Why didReceiveRemoteNotification:fetchCompletionHandler is called but usual didReceiveRemoteNotification isn't?为什么 didReceiveRemoteNotification:fetchCompletionHandler 被调用但通常的 didReceiveRemoteNotification 不是?
【发布时间】:2014-02-18 12:47:51
【问题描述】:

在我的应用程序中,我有两种类型的推送通知:带有content-available = 1 标志的远程静默通知和带有bodybadge 和其他东西的普通推送通知。

我还定义了两个委托方法didReceiveRemoteNotification:fetchCompletionHandler 和通常的didReceiveRemoteNotification

但是当没有content-available 标志的推送通知到达didReceiveRemoteNotification:fetchCompletionHandler 时,会调用didReceiveRemoteNotification,而不是didReceiveRemoteNotification

如何解决这个问题?
为什么我不能有两个委托方法来进行后台推送和常规推送?

【问题讨论】:

  • content-available 是否影响要调用的方法?我认为将remote-notification 设置为后台模式会导致didReceiveRemoteNotification:fetchCompletionHandler 调用。
  • "内容可用是否影响要调用的方法?" - 不。我说过but when usual push-notification without content-available flag arrives nevertheless didReceiveRemoteNotification:fetchCompletionHandler is called。因此,无论是否设置了 content-available 标志,都会调用此委托。
  • 那么,不是因为remote-notification后台模式。
  • @vokilam 据我了解“由于远程通知后台模式”iOS 将始终只调用新的 didReceiveRemoteNotification:fetchCompletionHandler 而不是 didReceiveRemoteNotification 并且没有办法改变这一点,对吧?
  • 我猜,没办法。因为通常的推送通知也可以在后台处理。

标签: ios objective-c cocoa-touch ios7 apple-push-notifications


【解决方案1】:

iOS 7 只调用新的,这是我在我的应用程序中处理它的方式:

-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    // Pass on
    [self application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:nil];

}

-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    // Check if in background
    if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive) {

        // User opened the push notification

    } else {

        // User hasn't opened it, this was a silent update

    }

}

【讨论】:

  • 感谢您的快速回答。你说:“iOS 7 只调用新的”,但为什么要这样做:` // 传递 [self application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:nil];` 如果这个方法不会被调用?
  • iOS 6 及更低版本仍然调用旧版本,因此在旧版本 iOS 上运行时只需将其传递给新版本...
猜你喜欢
  • 2015-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-11
相关资源
最近更新 更多