首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未调用didReceiveRemoteNotification

未调用didReceiveRemoteNotification
EN

Stack Overflow用户
提问于 2018-09-04 18:36:54
回答 1查看 108关注 0票数 0

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

My Capabilities here

My info.plist here

代码语言:javascript
复制
- (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:

代码语言:javascript
复制
    - (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;
  }
EN

回答 1

Stack Overflow用户

发布于 2018-09-06 19:34:43

文档:

用户通知框架Here

在iOS 11和更高版本中,方法didReceiveRemoteNotificationdeprecated

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

它可能看起来像这样

代码语言:javascript
复制
- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
   willPresentNotification:(UNNotification *)notification 
     withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler;

注意,iOS targets below 11仍然需要实现didReceiveRemoteNotification方法。

代码语言:javascript
复制
// 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 
   }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52164335

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档