1

I have a Phonegap App where I recieve Push Notifications. I send a "Pagekey" in the payload, which tells the App which HTML Page to open after the App starts on a received Push Notification.

I do the following in the - (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions (Snippets)

NSDictionary* extras = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
NSString *key = ((NSString*)[extras objectForKey:@"pagekey"]);//get the Pagekey
NSLog(@"key: %@", key); //prints out "2" (2 without the "")

//Load the HTML Page depending on the pagekey
self.viewController.wwwFolderName = @"www";
if([key isEqual:@"2"]){
    NSLog(@"Im in the 2 branch");
    self.viewController.startPage = @"winnings.html";
}else{
    NSLog(@"Im in the else branch");//this branch is executed(unexpected behaviour)
    self.viewController.startPage = @"index.html";
}

the pagekey was originally JSON Data, sent from a push notification server. Anyone knows how to compare the String properly so the correct branch is executed? thanks a lot in advance!

最白目
  • 3,505
  • 6
  • 59
  • 114

2 Answers2

1

Try if([key isEqualToString:@"2"])...

See this thread for information about isEqual vs isEqualToString

Community
  • 1
  • 1
Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
1

Use - (NSComparisonResult)compare:(NSNumber *)decimalNumber of NSDecimalNumber class.

if ([key compare:[NSNumber numberWithInt:2]]==NSOrderedSame) {
    //Equal
}
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144