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 ...
ios objective-c push-notification
Kex Jun 10 '15 at 15:39 2015-06-10 15:39
source share