MatterGoal
MatterGoal

Reputation: 16430

UrbanAirship pushNotificationDelegate never get called

I'm using UrbanAirship to manage notifications in my iOS App. I want to add some specific behaviour on how notification are managed, so I decise to implement the protocol UAPushNotificationDelegate on a custom handler.

In this protocol I just add some NSLog for testing purpose in these 2 functions.

- (void)displayNotificationAlert:(NSString *)alertMessage{
    NSLog(@"Foreground Alert");
}

- (void)launchedFromNotification:(NSDictionary *)notification{
   ....Here I added code to present an alert view...
}

Then in the AppDelegate method didFinishLaunchingWithOptions I've added the UrbanAirship configurations:

// UrbanAirship data
UAConfig *config = [UAConfig defaultConfig];
[UAirship takeOff:config];

// THE DELEGATE!
UANotificationDelegate *pushDelegate = [[UANotificationDelegate alloc]init];
[UAPush shared].pushNotificationDelegate = pushDelegate;

[UAPush shared].notificationTypes = (UIRemoteNotificationTypeBadge |
                                     UIRemoteNotificationTypeSound |
                                     UIRemoteNotificationTypeAlert );

And this is the testing curl call that I use to test my code.

   curl -X POST -u "_APPKEY_:_MASTERKEY_" \
   -H "Content-Type: application/json" \
   --data '{"device_tokens": ["_THETOKEN_"], 
   "aps": {"alert": "Hello!"}}' \
   https://go.urbanairship.com/api/push/

The notification get received by my device, but my custom methods are never get called. What I'm doing wrong?

Upvotes: 1

Views: 357

Answers (1)

CMash
CMash

Reputation: 2168

The pushNotificationDelegate property is weak so nothing is keeping your pushDelegate out of the garbage collection. You'll want to store that pushDelegate variable somewhere yourself to ensure it doesn't get dealloced.

Upvotes: 2

Related Questions