我有一个Phonegap应用程序,我收到推送通知。我在有效负载中发送一个“Pagekey”,告诉应用程序在应用程序启动收到的推送通知后打开哪个HTML页面。
我在- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
(片段)
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";
}
pagekey最初是从推送通知服务器发送的JSON数据。任何人都知道如何正确比较字符串,以便执行正确的分支?非常感谢!
答案 0 :(得分:1)
答案 1 :(得分:1)
使用- (NSComparisonResult)compare:(NSNumber *)decimalNumber
类的NSDecimalNumber
。
if ([key compare:[NSNumber numberWithInt:2]]==NSOrderedSame) {
//Equal
}