[英]didRegisterForRemoteNotificationsWithDeviceToken not called for iOS 13 (Objective C)
I am using below code to register for push notification alert.我正在使用以下代码注册推送通知警报。
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
NSLog(@"fapa=1");
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
NSLog(@"fapa=error==%@", error);
if(!error){
NSLog(@"fapa=registering now");
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"fapa=registering now 2");
[[UIApplication sharedApplication] registerForRemoteNotifications];
});
}
}];
Below is the place where I get token下面是我获得令牌的地方
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
However problem is this method is not called from iOS 13 (not sure whether for just iOS 13.4.1 or all iOS 13).然而问题是这个方法不是从 iOS 13 调用的(不确定是仅适用于 iOS 13.4.1 还是所有 iOS 13)。
Is anyone have idea why this is happening or Apple update something or this is a bug?有谁知道为什么会发生这种情况或Apple更新某些东西或这是一个错误?
Sorry for adding Swift tag, but just I add as mostly many developers filter SO with Swift questions only (even they know Objective C. So just to bring in attention, I add swift too. Sorry for adding Swift tag, but just I add as mostly many developers filter SO with Swift questions only (even they know Objective C. So just to bring in attention, I add swift too.
Something weird.有什么奇怪的。
From WIFI when I connect to mobile network, I got token & didRegisterForRemoteNotificationsWithDeviceToken start working.当我从 WIFI 连接到移动网络时,我得到了令牌和 didRegisterForRemoteNotificationsWithDeviceToken 开始工作。
Now when I go back to WIFI again didRegisterForRemoteNotificationsWithDeviceToken start working.现在,当我 go 再次回到 WIFI 时,didRegisterForRemoteNotificationsWithDeviceToken 开始工作。
What is this?这是什么? Did anyone face this weird issue?
有人遇到过这个奇怪的问题吗?
What I did is I put above code (of registering for push notification) in one function and call that function every 5 seconds.我所做的是将上述代码(用于注册推送通知)放在一个 function 中,并每 5 秒调用一次 function。 Surprisingly, I get token now, but token for iOS 13 onwards, token is not as I get before.
令人惊讶的是,我现在得到了令牌,但是 iOS 13 以后的令牌,令牌不像我以前那样。 I need to check further on this issue.
我需要进一步检查这个问题。 Once I check, I will post an answer for this question.
一旦我检查,我将发布这个问题的答案。
But calling register push function every 5 seconds did the trick.但是每 5 秒调用一次 register push function 就可以了。
What I did is I put above code (of registering for push notification) in one function and call that function every 5 seconds.我所做的是将上述代码(用于注册推送通知)放在一个 function 中,并每 5 秒调用一次 function。 Surprisingly, I get token now, but token for iOS 13 onwards, token is not as I get before.
令人惊讶的是,我现在得到了令牌,但是 iOS 13 以后的令牌,令牌不像我以前那样。 I need to check further on this issue.
我需要进一步检查这个问题。 Once I check, I will post an answer for this question.
一旦我检查,我将发布这个问题的答案。
But calling register push function every 5 seconds did the trick.但是每 5 秒调用一次 register push function 就可以了。
I am putting this answer as no one will understand Edit 1 I have above is the answer.我提出这个答案是因为没有人会理解我上面的编辑 1 就是答案。 Better to have an answer for the question.
最好有问题的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.