Kevin McFadden
Kevin McFadden

Reputation: 357

didFinishLaunchingWithOptions not Showing Initial Alert (PubNub)

I am trying to create a PushNotification app and I am working with PubNub. I have gone through all of the necessary steps to:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(     NSDictionary *)launchOptions
{
    // #2 Register client for push notifications
    NSLog(@" Options set");

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:    (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    [PubNub setDelegate:self];
    return YES;
}

After getting some initial compile errors, I was able run the app on my device. When I ran the app on my device, I did not receive the "...Would Like To Send Yo Push Notifications" message as I thought I should. I am able to use the PubNun console to send a message and I see the messages are received via the log, but I do not get any notification or banner. I placed an NSLog in the didFinishLaunchingWithOptions method and I see the display in the log.

After that, I deleted the app from the device, deleted the provisioning profile form the device, restated Xcode, and compile and an again with the same results. Not sure what to try next.

Upvotes: 0

Views: 394

Answers (2)

Mike
Mike

Reputation: 9835

EDIT: The specific problem you're running into has to do with the fact that you are running the application through Xcode, and in a nutshell you can't test production push notifications this way, you'd have to use the sandbox push server and certs. If you want to test prod pushes you'll need to distribute the application signed with an Ad Hoc provisioning profile. I'm sure there are a million ways to do this, but actually my two favorites are using Testflight and Crashlytics' new Beta feature, that allows you to distribute ad hoc builds to devices basically using a single line of code, automatically once you archive a new build. I would recommend Crashlytics because it also automatically handles extremely useful analytics as well as crash reporting.

If you are referring to the initial push notifications permissions pop-up, that will only be displayed once or the lifetime of the application. The ONLY way I believe to get around this is to uninstall the up and leave it uninstalled for 3 days (I believe this is the limit).

I'm unfortunately not familiar with PubNub, but in your application are you registering for push notifications and receiving a device token?

Upvotes: 2

Serhii Mamontov
Serhii Mamontov

Reputation: 4932

Kevin,

If this is all what you try to do, to receive notifications using PubNub service, than it is not enough. After you receive device push notification token, you need to pass it to PubNub client library, for example like this with default configuration:

- (BOOL)            application:(UIApplication *)application 
  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Initialise PubNub client.
    // Warning, you should use pub/sub/secret keys for your account (at admin.pubnub.com) to 
    // which you uploaded your development push notification certificate (in .pem file).
    [PubNub setupWithConfiguration:[PNConfiguration defaultConfiguration] andDelegate:self];
    [PubNub connect];

    UIRemoteNotificationType type = (UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound);
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:type];

    return YES;
}

- (void)                               application:(UIApplication *)application 
  didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

    [PubNub enablePushNotificationsOnChannel:[PNChannel channelWithName:@"my-test-channe-for-push-notifications"] 
                         withDevicePushToken:deviceToken];
}

// Observe for some PubNub delegate methods related to push notification observation (or use completion block enabled version of API):
- (void)pubnubClient:(PubNub *)client didEnablePushNotificationsOnChannels:(NSArray *)channels {

    NSLog(@"PubNub client enabled push notifications on channels: %@", channels);
}

- (void)pubnubClient:(PubNub *)client pushNotificationEnableDidFailWithError:(PNError *)error {

    NSLog(@"PubNub client failed push notification enable because of error: %@", error);
}

If you see that push notification enabling has been successful for you, then use http://pubnub.com/console with pub/sub/secret keys from your account at http://admin.pubnub.com to send message into the channel (in our case "aps" payload should be sent to the channel with "my-test-channe-for-push-notifications" name).

Upvotes: 1

Related Questions