on master help sign in
Merge pull request #56 from samtay/master

Allow badge updates while app is in foreground

commit6a8fbe20cfd4ea00e197acdf311a650b97cb9a61 authorHamish Mackenzie <Hamish.K.Mackenzie@googlemail.com> dateThu 15 Feb 2018, 17:15 (9 years ago) parent50126cde9df19e
1 file changed+9
jsaddle-wkwebview/cbits-uikit/AppDelegate.m+9
jsaddle-wkwebview/cbits-uikit/AppDelegate.m+9
@@ -109,6 +109,15 @@ HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
109109 callWithCString([deviceTokenString UTF8String], global_didRegisterForRemoteNotificationsWithDeviceToken);
110110}
111111
112+- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
113+ // Sent when the application receives remote notifications in the foreground or background
114+ // TODO Allow a configurable CString -> IO () to be passed into AppDelegateConfig
115+ if ([userInfo valueForKeyPath:@"aps.badge"] != nil) {
116+ [UIApplication sharedApplication].applicationIconBadgeNumber=[[[userInfo objectForKey:@"aps"] objectForKey:@"badge"] intValue];
117+ }
118+ completionHandler(UIBackgroundFetchResultNewData);
119+}
120+
112121- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
113122 // Sent to the delegate when Apple Push Notification service cannot successfully complete the registration process.
114123 NSString *errorString = [error localizedDescription];