Push notifications that trigger background updates before showing push notifications VS silent push

I want to implement the background update function in my application when push is received. Before a push notification is sent to the user, I want to download new messages from my server (Parse.com) and save them in an array. I follow the guide from here: http://developer.xamarin.com/guides/ios/application_fundamentals/backgrounding/part_3_ios_backgrounding_techniques/updating_an_application_in_the_background/

I'm not sure how accurate this guide is. It says: iOS 7 (and above) extends the usual push notifications, giving applications the ability to update content in the background to , notifying the user so that the user can open the application and receive new content immediately.

So, I tried to implement my background output as follows:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler { if([[userInfo objectForKey:@"aps"] objectForKey:@"content-available"]){ NSLog(@"Doing the background refresh"); UINavigationController *navigationController=(UINavigationController *)[[[UIApplication sharedApplication] keyWindow] rootViewController]; MyViewController *myViewController = (MyViewController *)[[navigationController viewControllers] objectAtIndex:1]; [myViewController.currentUser refreshMessagesArrayWithCompletionHandler:^(BOOL successful, BOOL newMiaos) { NSLog(@"messages refreshed the array now has %lu messages",(unsigned long)[myViewController.currentUser.messages count]); handler(UIBackgroundFetchResultNewData); }]; } } 

A background update is called and push is displayed, but the push notification does not wait for the background task to complete. It is displayed only after receiving it. Is this the correct functionality? The above guide says that a notification will not be displayed until the background task completes.

Then I started trying a silent notification, this causes the application to download messages in the background when a notification is pressed but not displayed. So I do this by opening a local notification after the download is complete. Is this really the right way to do this? How do traditional apps like whatsapp trigger background updates via silent notification and then launch local? Seems a bit hacky. Of course, the idea of ​​background clicking is to prepare the data before the notification is displayed, but this is not entirely true.

Another thing I noticed is that silent notifications are limited in speed, they have a lower priority than a typical push notification, so this certainly interferes with application performance ...

Any pointers to this would really be appreciated. Just trying to lower my head if I approach this correctly or not. Everything seems very hacked ...

+23
ios objective-c push-notification
Jun 10 '15 at 15:39
source share
2 answers

I struggled with the same task in my messaging app . We wanted users to see the message right before the user deletes the notification. What we faced:

  • Payload size limitation. iOS 7 can only have 256 bytes for payload
  • single silent notifications do not start the application if it does not work
  • content-available notifications without a warning body can even be delivered to the device
  • Background sampling is not controlled by your application, so you can never get the desired signal, so we can not rely on this function. But this can be useful as an additional way to achieve the desired.
  • iOS 8 has plenty of payload space - 2K
  • if you send a warning body and content-available , it will be delivered in most cases, and the application will be able to process it.

So, we came to the only acceptable solution: we decided to make this function only in ios8 +. We send visible push notifications using the content-available key, which allows us to handle the notification payload if the process is running / frozen, and both can provide a notification if the application is not running. If the application receives a push notification, it receives the body of the blogs and writes it to the local database, so the user can read it in a conversation. According to our statistics, the average message size is not more than 200 characters, so in most cases additional requests are not required. If the message is longer than 200 characters, we extend the payload body with an additional parameter, which is used to request the text body in the processing of push notifications. The user will see a cropped version of the text, but after executing the request, we rewrite the message in the local database with the received value.

Thus, this method allows us to immediately display the received message to the user in most cases +, if the application was not launched, we make a request to our server to receive missing messages immediately after launching the application. This is the fastest and most acceptable case that we could get on iOS. I hope my experience will help you realize what you want.

+15
Jun 14 '15 at 21:08
source share

You mixed a few things together.

With a quick look at your link, this is a guide for xamarin . There may be some correct information, but if you are not using xamarin , I would look for another tutorial.

A good approach would be to send a silent notification to the user and trigger a local notification when it is executed (which is not hacks at all).

Here's how whatsApp works:

While whatsApp is in the background, one push notification is received (for example, β€œ5”). msg will not be displayed to the user.

whatsApp receives it in the application:didReceiveRemoteNotification:fetchCompletionHandler: and checks their servers if there are any notifications up to "5" that the user has not received. In this case, they will retrieve this data from their servers and will present it to the user using local notifications, which are mainly a way of presenting data and are generally not associated with APNS.

You can read the full answer and context in another answer I wrote here

+8
Jun 14 '15 at 20:11
source share



All Articles