1

The same source code works fine i Xcode 7.3.1, but when I compile with Xcode 8.1, then I never receive any push notifications

YES, I have enabled the Settings->Targets->Capabilities->PushNotifications.

And, YES, these two methods are are called: didRegisterUserNotificationSettings didRegisterForRemoteNotificationsWithDeviceToken

I am testing on device iPhone 6S, iOS 10.1.1 I have cleaned the build

I tried some suggested solutions from stackoverflow, suggesting using UNUserNotificationCenter, but of no help.

What could possibly be wrong?

OMH
  • 775
  • 1
  • 10
  • 23
  • 1
    So many possibilities, need more information to answer. Are you testing on a real device? What does your notification payload look like? Have you cleaned and then built? Are you using the new automatic signing? What device? How are you sending the push? Are you updating the device token which is quite possibly different than it was when compiled for Xcode 7? Without that info it will be hard to reproduce your issue and see what's going wrong :) – Jordan Smith Nov 15 '16 at 20:52
  • @JordanSmith Could you please say something about the "Are you updating the device token which is quite possibly different than it was when compiled for Xcode 7?" Maybe this could be the issue. Why should this be different between Xcode 7 and 8? – OMH Nov 15 '16 at 21:06
  • 1
    The app token will not be "quite possibly different" it 100% definately will be different. And wants more it will change every time you run the app now. So how are you getting the token from the device to your server? – Gruntcakes Nov 15 '16 at 21:09
  • 1
    It can definitely change, see here: http://stackoverflow.com/questions/6652242/does-the-apns-device-token-ever-change-once-created @Essenceofchickens hmm, are you sure? (i.e. is this a new thing on iOS 10?) Up until now it changed roughly every day or so. This is why I said 'possibly'. – Jordan Smith Nov 15 '16 at 21:27
  • 1
    With older version of iOS it would change very very rarely (a trigger would be backup/restore from iTunes). Now in iOS 10 it changes much more frequently, I made a typo, I didn't mean everytime it is run, I meant every time the app is installed (which didn't used to be the case). But it will defiantly change when going from the old app to the new one in any case. – Gruntcakes Nov 15 '16 at 21:31
  • @Essenceofchicken How do I get the token from device to server? - (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{ #if !TARGET_IPHONE_SIMULATOR NSString *dToken = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<" withString:@""] stringByReplacingOccurrencesOfString:@">" withString:@""] stringByReplacingOccurrencesOfString:@" " withString:@""]; self.devToken = dToken; [self sendToServerDevToken]; #endif } – OMH Nov 17 '16 at 07:55
  • @Essenceofchicken (lldb) po deviceToken <2ef98ed3 9fe6e6d1 5f84f258 c380e12f 3dfea71b 8c5824ba 14b35e98 1f582310> (lldb) po dToken 2ef98ed39fe6e6d15f84f258c380e12f3dfea71b8c5824ba14b35e981f582310 This happens every time the app is run. On next run, it's the same, e.g po deviceToken <2ef98ed3 9fe6e6d1 5f84f258 c380e12f 3dfea71b 8c5824ba 14b35e98 1f582310> – OMH Nov 17 '16 at 07:57
  • @JordanSmith I hope I explained client side. Will ask server guy when he available. – OMH Nov 17 '16 at 08:02

1 Answers1

1

You can use below two delegate for iOS10 with this delegate name UNUserNotificationCenterDelegate

For Swift:

func userNotificationCenter(_ center: UNUserNotificationCenter,  willPresent notification: UNNotification, withCompletionHandler   completionHandler: @escaping (_ options:   UNNotificationPresentationOptions) -> Void) {

print("\(notification.request.content.userInfo)")}

 func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

print("\(response.notification.request.content.userInfo)")}
Bucket
  • 449
  • 3
  • 20
  • Thanks. but I tried this earlier, and neither of these methods were called. – OMH Nov 16 '16 at 07:36
  • 1
    You must contact with your php developer, first provide your token id to your php developer and tell him to send one test notification from server on your current device, this way you can verify whether issue is from your side or php side. – Bucket Nov 16 '16 at 08:23
  • I sent many test notifications from server, but none was received when the iOS client was built with Xcode 8 – OMH Nov 21 '16 at 14:12
  • have you try with application on kill mode i mean when app was inactive ? – Bucket Nov 21 '16 at 15:27