【问题标题】:didReceiveRemoteNotification not invoked未调用 didReceiveRemoteNotification
【发布时间】:2018-09-04 10:36:53
【问题描述】:

我正在使用 Salesforce Marketing Cloud iOS SDK (v4.9.7)。我能够接收推送通知并能够调用“didReceiveNotificationResponse”。但我无法调用“didReceiveRemoteNotification”。可能是什么问题?

My Capabilities here

My info.plist here

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

  [[ETPush pushManager] handleNotification:userInfo forApplicationState:application.applicationState];




  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Do you want to say hello?"
                                                  message:@"More info..."
                                                 delegate:self
                                        cancelButtonTitle:@"Cancel"
                                        otherButtonTitles:@"Say Hello",nil];
  [alert show];
}

我的 AppDelegate:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
    [self application:application shouldInitETSDKWithOptions:launchOptions];

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    {
      UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil];
      [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

    }
    else
    {
      [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
       (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    }

    [[ETPush pushManager] setCloudPageWithAlertDelegate:self];
    [[UIApplication sharedApplication] registerForRemoteNotifications];

    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;

    return YES;
  }

【问题讨论】:

  • 您的设备中是否收到通知?你是否在 appdelegate 中注册了推送通知?
  • 您的通知负载是否包含content-available?如果不是,您可能想看看这个Documenation Payload JSON for APNS 和App Delegate Implementation 您可能还想知道,从 iOS 11 开始,您使用的这种方法已被弃用。
  • @FaysalAhmed 是的,我在我的设备中收到了通知。我在 appdelegate 中注册了推送通知作为上面的更新帖子。
  • @user1171911 它在我更改为“willPresentNotification”后工作。谢谢!!!!
  • @Fiona 很高兴来到这里,我将在答案中发布相关文档,因为它解决了问题。我假设它有效,因为您的目标 iOS 是 11+?

标签: objective-c salesforce-marketing-cloud


【解决方案1】:

文档:

用户通知框架:Here

从 iOS 11 起,方法didReceiveRemoteNotification 是deprecated。

接下来,使用UserNotifications 框架方法:userNotificationCenter:willPresentNotification:withCompletionHandler:

可能是这样的

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
   willPresentNotification:(UNNotification *)notification 
     withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler;

注意 iOS 目标 below 11 仍需要实现 didReceiveRemoteNotification 方法。

// in app delegate file at top 
#if canImport(UserNotifications)
import UserNotifications
#endif
class AppDelegate { // ... abbreviated  }

@available (iOS 11, *)
extension AppDelegate: UNUserNotificationCenterDelegate {
   func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
      // your code to handle 
   }
}

【讨论】:

    猜你喜欢
    • 2017-03-28
    • 2020-06-30
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多