3

I am trying to develop an iOS app using UrbanAirship. I receive push notifications but cannot get any delegate to be called when the app is in the background. I (wrongfully it seems) assumed that the handleBackgroundNotification API from the UAPushNotificationDelegate class would provide me the functionality to execute custom actions when receiving the notification when app is in the background.

This is what their documentation says: "handleBackgroundNotification:

Called when a push notification is received when the application is in the background

- (void)handleBackgroundNotification:(NSDictionary *)notification

Parameters

notification

the push notification

" - see https://docs.urbanairship.com/ios-lib/Classes/UAPushNotificationHandler.html#//api/name/handleBackgroundNotification:

Doesn't seem to work that way - sure seems the OS is keeping the notification for itself - which is inline with Apple's documentation.

I am questioning the purpose of the function if the OS doesn't allow it. I use didReceiveRemoteNotification for receiving remote push notifications which works just fine!

However, since this is an enterprise application (i.e. not App Store), if there are private APÏs and frameworks that would allow me to do this, I would appreciate any assistance. There is no way this app would ever make it to the app store!

The custom actions I am trying to execute include, for example, a notification receipt sent to a server that would "prove" the recipient app did indeed receive the notification, play a custom sound at maximum volume (bypassing silence and do not disturb mode). These are some requirements from the client.

Kara
  • 6,115
  • 16
  • 50
  • 57

2 Answers2

1

This is what I use and its working just fine:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if(!loggedIn) return;

    NSLog(@"WOW: got notification! %@", userInfo);

    // see this for fine tuning: http://fivelakesstudio.blogspot.com/2012/04/push-notifications-and-urban-airship.html
    [[UAPush shared] handleNotification:userInfo applicationState:application.applicationState];
    [[UAPush shared] resetBadge];

    sharedApplication.applicationIconBadgeNumber = 0;   // probably redundant

    [self handlePushNotification:userInfo isBooting:NO]; // my common handler
}
David H
  • 40,852
  • 12
  • 92
  • 138
  • Sorry but not what I'm looking for - essentially I need to understand how handleBackgroundNotification from UAPushNotificationDelegate works in terms of being notified of a push notification while the app is in the background. Their documentation claims that's what it can do but I have my reservations... – user1671934 Nov 15 '12 at 01:07
  • `didReceiveRemoteNotification` is called when your app is in the foreground, or brought into the foreground when your aps message has been tapped. APNS handles the icon badging - your app is not brought into the foreground until there is user interaction. – Kent Jan 18 '13 at 05:12
0
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
UA_LINFO(@"Application received remote notification: %@", userInfo);
[[UAPush shared] appReceivedRemoteNotification:userInfo applicationState:application.applicationState fetchCompletionHandler:completionHandler];

NSDictionary *values = [userInfo objectForKey:@"aps"];
NSString *title = [values objectForKey:@"alert"];

}

process the notification received for all states in this block. NB. you can monitor the application.applicationState value to note the state of the app when the notification is received. Hope this helps

Farai
  • 180
  • 2
  • 12