Ios 当应用程序从关闭状态通过通知滑动启动时,不会调用didReceiveNotificationResponse方法
我观察到,当我通过推送通知滑动从后台重新启动应用程序时,会调用Ios 当应用程序从关闭状态通过通知滑动启动时,不会调用didReceiveNotificationResponse方法,ios,objective-c,push-notification,apple-push-notifications,salesforce-marketing-cloud,Ios,Objective C,Push Notification,Apple Push Notifications,Salesforce Marketing Cloud,我观察到,当我通过推送通知滑动从后台重新启动应用程序时,会调用didReceiveNotificationResponse方法。但当我关闭应用程序并通过推送通知刷重新启动时,它没有被调用 - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHan
didReceiveNotificationResponse
方法。但当我关闭应用程序并通过推送通知刷重新启动时,它没有被调用
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler
{
// Sending analytics to my server
}
我正在通过我的分析后端验证这一点,我可以通过通知刷从后台看到所有的发布都得到反映,但另一个没有。在这两种情况下,我使用的是相同的API,因此理想情况下应该对其进行更新
以下是我的didfishlaunchingwithoptions
方法:
-(BOOL)application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
dispatch_async(dispatch_get_main_queue(), ^(void){
//Run UI Updates
if (@available(iOS 10, *)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) {
if( !error ) {
// required to get the app to do anything at all about push notifications
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] registerForRemoteNotifications];
});
NSLog( @"Push registration success." );
} else {
NSLog( @"Push registration FAILED" );
NSLog( @"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription );
NSLog( @"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion );
}
}];
}
});
添加我从第三方服务提供商(Salesforce)获得的通知内容:
我还从后台模式启用了远程通知
点击通知时,应用程序的状态是什么?它是否未启动?您需要使用启动选项检查应用程序是否通过通知启动,并基于此检查通知数据。我看到了该解决方案的几个答案。但是,要使我的分析工作正常,我需要传递通知.response.notification.request
。我不会从启动选项[UIApplicationLaunchOptions sRemoteNotificationKey]
获取此数据,对吗?有什么办法可以做到吗?然后我可以从自定义函数处理它。notification.response.notification.request的内部是什么?您可以在启动选项中获取有关通知的所有信息。当您点击通知时,应用程序的状态是什么?它是否未启动?您需要使用启动选项检查应用程序是否通过通知启动,并基于此检查通知数据。我看到了该解决方案的几个答案。但是,要使我的分析工作正常,我需要传递通知.response.notification.request
。我不会从启动选项[UIApplicationLaunchOptions sRemoteNotificationKey]
获取此数据,对吗?有什么办法可以做到吗?然后我可以从自定义函数处理它。notification.response.notification.request的内部是什么?您可以在启动选项中获取有关通知的所有信息。
{
"_h" = "V6bdjs7jjkqv/POIIIII";
"_m" = MjJhJkKkK;
"_mt" = 1;
"_r" = "9dsdsjkk-3344dd-4edd-ade33-jhdj999";
"_sid" = SFMC;
aps = {
alert = {
body = test;
subtitle = "Push Test";
title = "Push Test";
};
"mutable-content" = 1;
sound = default;
};
}