Reputation: 1389
Our server sends push notification with content-available. UIBackgroundMode is allowed for push notification. Everything works well in debug mode whether the application is in the foreground or in the background (pressing home button). The delegate didReceiveRemoteNotification is called in both scenarios.
However, if the application is not connected to the debugger and in the background, it is never called. When I press on any of the notifications, it gets called which does not give me any time to download content in advance as it is supposed to do. Can it be that we are using a development certificate instead of production? What other reason can cause something like that to happen? (If you would like me to provide any snippet to find the issue, kindly let me know)
Any help is appreciated
Upvotes: 4
Views: 849
Reputation: 2298
I have been also facing same problem, every methods works fine in debugging mode but fails to run when not debugging.
You need to remove check of UIApplication.State.background
in below method(if any).
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
Upvotes: 0
Reputation: 31
Are you add these register support lines
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Register the device with APNS and specify which notification types are supported: [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
return YES; }
// Called when the registerForRemoteNotificationTypes method completes: - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { } - Now generate your push notification certificates like .p12 if you want to check from client side (without server) then use Pusher application to generate notification .if your certificates are valid then you get notification . - To generate notification certificates follow http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1 link.
Upvotes: 0
Reputation: 31
** Go to capabilities and turn on background Mode then select background fetch , Remote notification options. if you are using ios 8 then use**
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
method instead of
Upvotes: 2