1

我有一个 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 数据,从推送通知服务器发送。任何人都知道如何正确比较字符串以便执行正确的分支?提前非常感谢!

4

2 回答 2

1

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

有关 isEqual 与 isEqualToString 的信息,请参阅此线程

于 2012-09-10T14:13:01.430 回答
1

类的使用- (NSComparisonResult)compare:(NSNumber *)decimalNumberNSDecimalNumber

if ([key compare:[NSNumber numberWithInt:2]]==NSOrderedSame) {
    //Equal
}
于 2012-09-10T14:45:09.157 回答