我有一个失败的简单条件:
NSNumber *beaconMajor = [NSNumber numberWithInt:33995];
NSNumber *beaconMinor = [NSNumber numberWithInt:59204];
NSNumber *incommingMajor = beacon.major;
NSNumber *incommingMinor = beacon.minor;
NSLog(@"%d", [beaconMajor integerValue]);
NSLog(@"%d", [incommingMajor integerValue]);
NSLog(@"Pre big conditional");
//if the beacon is the one for the test content AND we are very near to it, show that content
if (incommingMinor == beaconMinor) {
NSLog(@"Into big conditional");
if (beacon.proximity == CLProximityImmediate) {
[self performSegueWithIdentifier:@"mainToContent" sender:self];
}
}
我正在从 iBeacon 中获取两个 NSNumbers,并将它们与我知道对应的两个手动设置的数字进行比较。当我记录它们时检查数字,它们是相同的。但是,条件不接受它们相等,因此不会触发。
我看不出有什么不对,就像你看到的那样很简单。
有什么想法或建议吗?
谢谢。
最佳答案
你在比较对象(内存中的地址),你需要比较它们的值:
if ([incommingMinor intValue] == [beaconMinor intValue])
关于ios - 简单的条件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20119699/