0

I have researched enough before asking this question.
I work with GCM[Google Cloud Messaging] for push notifications.

this is the message which I send from GCM

{
"to" : "....",
"notification": {
"sound": "default",
"badge": "1",
"title": "A Message Received",
"body": "Please open messages",
},
"content_available":true,
"priority": "high",
"data":{
"message":"heey"
}
}

as I have read from other sites, it told if you want a silent notification put content_available in the headers, and it would work correct.
everything is fine and working with this method.
but the only problem is when application has been forced closing by user. it can not handle the code in

func application( application: UIApplication,
    didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
    fetchCompletionHandler handler: (UIBackgroundFetchResult) -> Void) {
}

in other question that has an answer said there is no solution for it. except pushkit in IOS 8.

some told this link can help: https://zeropush.com/guide/guide-to-pushkit-and-voip
but I couldn't use it. some steps are not clear.

My Request is if anyone know the best solution or a piece of code for PushKit framework or anything that can help me.

  • Did you ever find an answer to this? I'm having a similar problem where I can't respond to pushes when the app is killed and a user launches the app from the app icon and not the push. – VeganKid May 11 '16 at 01:07

1 Answers1

0

Method:

func application( application: UIApplication,
     didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
            fetchCompletionHandler handler: (UIBackgroundFetchResult) -> Void) {
}

works if app is suspended and in background. That method is for iOS 7 and above. When app is not running didFinishLaunchingWithOptions is called. You can do something like this in this method:

 UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (notification) {
    NSLog(@"app recieved notification from remote%@",notification);
    [self application:application didReceiveRemoteNotification(NSDictionary*)notification];
}else{
    NSLog(@"app did not recieve notification");
}

as found here: Detect if the app was launched/opened from a push notification

For the VoIP push in iOS 8 PushKit first you need to create certificates. This example helped me so check it out: https://www.sinch.com/tutorials/ios8-apps-and-pushkit/ It's really straight forward.

Community
  • 1
  • 1
Flipper
  • 1,097
  • 1
  • 10
  • 30
  • Thanks for the answer. but the problem didFinishLaunchingwithOption is user have to click on notification. but in my case I have a notification that have to show a notification in future. like a message for future but the push notification sent to device at compose time. – Ehsan Razm khah Nov 10 '15 at 19:41