Matteo Matteo - 1 year ago 84
iOS Question

Push Parse - launchOptions is null in didFinishLaunchingWithOptions

I know that this is a question already answered.

but after reading a lot of messages my problem is still here.

Using parse i sent this json push:

{"aps" : { "alert" : "text msg", "badge" : 1, "sound" : "chime" }, "_3Y" : "0"}

If app is active, then is all right, userInfo receive my data correctly:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
[PFPush handlePush:userInfo];

If the app is idle, the badge and the text notification appears but:

If I click on the text on notification bar, the app starts and I receive the push

If I click on the badge, the app starts but launchOptions in didFinishLaunchingWithOptions is null!

This is my test code for didFinishLaunchingWithOptions method:

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

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

NSDictionary *aPushNotification = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
// NSDictionary* aPushNotification = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];

NSString *test = [aPushNotification objectForKey:@"_3Y"];

[[[UIAlertView alloc] initWithTitle:test message:[aPushNotification description] delegate:NULL cancelButtonTitle:NSLocalizedString(@"LOC018", @"Ok") otherButtonTitles:nil, nil] show];

Maybe is a Parse problem ?

Any help would be appreciated..

Thanks in advance!!

Answer Source

launchOptions is only set if the application is launched through the notification, if you launch it through the badge on the icon it starts without arguments, with launchOptions = nil.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download