Gerald Eersteling
Gerald Eersteling

Reputation: 1284

Not receiving push form Urban Airship on iOS

I'm trying to get my iOS devices to receive push notifications again, but it's not really working out.


The context in which I'm working:

My project setup

My code


Here are a few snippets of my code:

(in applicationDidFinishLaunching:)

if (UNUserNotificationCenter.class) {
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge)
                          completionHandler:^(BOOL granted, NSError * _Nullable error) {
                              if (!error) {
                                  [[UIApplication sharedApplication] registerForRemoteNotifications];
                              } else {
                                  DLog(@"There was an error trying to request authorization for push: %@", error);
                              }
                          }];
} else {
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings
                                                                         settingsForTypes:(UIUserNotificationTypeAlert
                                                                                           | UIUserNotificationTypeSound
                                                                                           | UIUserNotificationTypeBadge)
                                                                         categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}

UAConfig *config = [UAConfig config];

config.inProduction = self.urbanAirshipInProduction;

if(self.urbanAirshipInProduction) {
    config.productionAppKey     = self.urbanAirshipKey;
    config.productionAppSecret  = self.urbanAirshipSecret;
} else {
    config.developmentAppKey    = self.urbanAirshipKey;
    config.developmentAppSecret = self.urbanAirshipSecret;
}

[UAirship takeOff:config];

UAPush *pusher = [UAirship push];

pusher.notificationOptions = (UANotificationOptionAlert |
                              UANotificationOptionBadge |
                              UANotificationOptionSound);
pusher.pushNotificationDelegate = self;
pusher.userPushNotificationsEnabled = YES;

With the above code I was expecting to receive calls to applicationDidReceiveRemoteNotification:fetchCompletionHandler: and UNUserNotificationCenterDelegate methods for iOS10.

But alas, none of them methods even dared to get called.


I have no clue as to why push won't get pushed to my devices. I checked the App in UA and Installed, Opted in and Background are all green when I search for my device token.

The problem arises with both iOS 8,9 and iOS10. But I'm not sure if this is really an OS thing.

Why?

Because I found a support ticket here and somewhere to the bottom "aboca_ext" (just search the page for his/her username) says:

Hi guys, I found my problem, I was cleaning up my cache when my application was starting, but after UA initiated sqlite db, and by this I was deleting their db. After I fixed that, everything worked as it should.

Now that's interesting because my project also uses SQLCipher, I'm wondering if that produces some kind of conflict (even though I'm not clearing any cache or whatsoever), but I'm not seeing any errors produced by either SQLCipher or UA.
Another funny (actually not so funny) note is that I think UA actually started failing after installing it using Cocoapods, but again--I'm not really sure if that's the problem.

Upvotes: 0

Views: 813

Answers (1)

ralepinski
ralepinski

Reputation: 1766

The Urban Airship SDK takes care of registering with UNUserNotificationCenter for you. You should be able to remove registration calls. I don't think it should be causing problems for you, but it could prevent some features such as OOTB categories from working.

As for push notification events, I would recommend listening using the push delegate on the UAPush instance instead of the factory methods or the UNUserNotificationCenter. The UA delegate methods are called across all OS versions. Hopefully it will help simplify your event handling code.

Deleting the sql lite database could cause some issues with reporting, but I would expect push to continue to work. Could you turn on verbose logging and the channel registration payload to see if opt_in is set to true? You can enable verbose logging on the UAConfig object.

Upvotes: 1

Related Questions