-->

iOS8.1.2 didReceiveRemoteNotification method not c

2019-06-09 06:46发布

问题:

In iOS version is 8.1.2,I found a really strange issue:
I implement below method to handle push info in appDelegate

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

If your device is not plugged in,this method is not called.

回答1:

If you look around, you'll see that others thought it would be a bug in iOS 7.1 beta, fixed in 7.1 release version, but it has probably nothing to do with any beta, Testflight, specific 8.1.2 version etc, like you say in your answer. I'm pretty sure this is the only correct answer. By the way, I have the same issue, but in 8.1.3, so I guess it will reappear with you too.

Once you delete the app, restart your phone, and install the app, the didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler: is called perfectly fine (which explains the "Use tesflight!", "in 7.1.x it works!", etc), but if you do too much calculations as a result of receiving the remote notification or not calling the completion handler on time, the system will not like you anymore and start calling the method later when it wants to, which will generally be 0-30 minutes after your notification has been received, or veeery long (see update below). With me, sometimes that happened already after the first remote notification. Unless, of course, the device is plugged in, then it will be much more reliable.

Once you reconnect (plug in) the device, the system might then call your method, generally it takes up to 15 minutes before it gets called, or it might just work instantly if you push the same notification an hour later but that also is not sure. It's really a pain, but don't think about it as something that will be fixed or so, it's the way Apple created it.

UPDATE: It will be called eventually. I sent a remote notification at 18.13h, and didReceiveRemoteNotification:fetchCompletionHandler: was not called until 09.41h the next day. So in my case, it took 15.5 hours until the method was called. In my case, the reason for that is probably that I use remote notifications to start and stop location tracking in the background, which is heavy stuff.



回答2:

After fount another answer about this problem,I am confirmed this really is a bug in iOS 8.1.2. I'm very surprised there isn't much thing about it on the internet.

But through my test,it has nothing to do with provision profile,using Apple's TestFlight does not work.