1

We want to create a ios application, whose working is mainly depends on Apple push notification. We have created server for this and server sends message successfully. But the problem is that application won't receiving messages when it goes background and not connected xcode for silent push messages. At the same time it works properly when it connected to xcode through usb.

The Json payload I had send from server as follows

 {"aps":{"content-available":1},"data":"hai"}

Code written "didReceiveRemoteNotification" is

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

    DEBUG_LOG(@"Remote notification received from server, silent mode");

    if(application.applicationState == UIApplicationStateInactive) {
        DEBUG_LOG(@"Application is not active now, suspended state");
        [self callNotificationMethod:@"Inactive"];

    } else if (application.applicationState == UIApplicationStateBackground) {
        DEBUG_LOG(@"Application is not active now, background state");
        [self callNotificationMethod:@"Background"];
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"CallOriginatedEvent"
                                                        message:@""
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"showTitle", nil];
        [alert show];
    }
 completionHandler(UIBackgroundFetchResultNewData);
}

Testing platform OS version : IOS 8.1 and above Devices:iPhone 5C,iPhone 5S,iPhone 6, iPhone 6+

Please advise.. Thanks in advance

user2067201
  • 258
  • 1
  • 13
  • I believe i have nothing to do with connection to xcode. – rptwsthi Jul 24 '15 at 12:37
  • We have enabled background mode - Remote notification, not working when device is unplugged from system(usb debugging) – user2067201 Jul 24 '15 at 12:39
  • Share the code where that you are using to handle notification. I mean code written inside: `- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken` and `- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo` – rptwsthi Jul 24 '15 at 12:43
  • Thanks for your attention. In the second method we just create a local notification and schedule it. – user2067201 Jul 24 '15 at 12:51
  • Have you implemented `- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler` ? Please show this code – Paulw11 Jul 24 '15 at 12:55
  • @user2067201 Happy to help! – rptwsthi Jul 24 '15 at 13:11
  • @rptwsthi: code written in "didReceiveRemoteNotification" is added. Can u see any issues in it. Please advise – user2067201 Jul 27 '15 at 12:01
  • Check [this similar question](http://stackoverflow.com/questions/19239737/silent-push-notification-in-ios-7-does-not-work), maybe it helps... – Baris Akar Jul 30 '15 at 08:59

2 Answers2

0

I think that your solution is pretty simple - you created dev certificate. Try creating production one and it should be fine.

Beside this solution, you should check:

  • have you registered for remote notifications?
  • do you have proper code in applicationDidFinishLaunchingWithOptions
  • do you send proper notification.
Miknash
  • 7,888
  • 3
  • 34
  • 46
  • Thanks for your reply. We are testing with dev certificate. Does it make issues? – user2067201 Jul 24 '15 at 12:50
  • Well, yeah, I had similar issues and lost my head over it. To be more problematic, if you distribute app through crashlytics or something else, you will see that your push notif are not working. Try to intercept error in func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) (just send the error message to server ) and you will be able to get more info – Miknash Jul 24 '15 at 12:52
  • Hi, I had created production certificate and send notification successfully when the app is in foreground. But not working when application is background. – user2067201 Jul 27 '15 at 11:35
  • Issue exits only for silent notification with app on background mode. Alert, badge, sound are working. – user2067201 Jul 27 '15 at 11:44
  • Have you checked DidRecieveRemoteNotificationFunction? – Miknash Jul 27 '15 at 11:46
  • how does your issue behave ? nothing happen after notification ? – Miknash Jul 27 '15 at 13:54
0

When I disconnect my iphone from USB, silent notification was not working for me, once I added priority to APNS notification like below it started working without USB connection.

{"aps":{'content-available' =>1 ,'priority' =>10},"data":"test"}

shamna
  • 111
  • 1
  • 6