ios - didReceiveNotificationResponse method is not called when the app gets launched through notification swipe from a closed state
问题描述
I have observed that didReceiveNotificationResponse
method is called when I re-launch the app from the background through a push notification swipe. But it is not getting called when I closed the app and re-launched through a push notification swipe.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler
{
// Sending analytics to my server
}
I am verifying this through my analytics backend and I can see all the launches from the background through notification swipe are reflected but the other one is not. In both cases, I am hitting the same API, so ideally it should get updated.
The following is my didFinishLaunchingWithOptions
method:
-(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 );
}
}];
}
});
Adding my notification content I am getting from a third-party service provider (Salesforce):
{
"_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;
};
}
I have enabled Remote Notifications
from Background Modes
also.
解决方案
推荐阅读
- python - Python从内存中运行exe
- reactjs - 我如何通过钩子使用正则表达式验证输入字段的反应
- flutter - 构建 Dart 对象的正确方法是什么?
- spring-mvc - 无法解析 JSTL 依赖项 - Tomcat 500 内部错误
- c# - 使用 wsl 以编程方式在 Windows 终端中执行命令
- r - Cook 的 Beta 回归距离
- karate - 空手道 - 从 json 文件中读取数据并将其分配给动态生成的请求
- python - 为什么 val_loss 和 val_accuracy 没有出现在时代
- jhipster - 我正在启动我的 JHIPSTER maven 服务器,但出现错误
- python - 如何在Python中找到未来时间的纪元时间