当我在 iPhone 5s 或更高版本上运行这段代码时,它按预期执行。但是当我在低于 5s(5、4s、4)的任何版本上运行它时,它不会。
应该进入第一个if语句,忽略第二个if语句并执行else。这在模拟器中超过 5s 的任何版本中都可以正常工作,但是当我在 5 或 4 上运行它时,它会进入第二个 if 语句...而不是忽略它并执行 else。
currentProduct.productID 是一个 NSNumber
任何可以帮助我的人都将不胜感激!
NSNumber *currentProductID = [[NSNumber alloc] initWithInt:4121];
if (productPurchased != YES) {
if (currentProduct.productID != currentProductID) {
[self performSegueWithIdentifier:@"InAppPurchaseViewController" sender:nil];
} else {
[self showActivityView];
[self performSelector:@selector(configureExam) withObject:nil afterDelay:0.1];
}
最佳答案
您不能使用 !=
(或 ==
)来比较两个对象。
将 if
更改为:
if (![currentProduct.productId isEqual:currentProductID]) {
旁注,使用现代语法来创建数字:
NSNumber *currentProductID = @4121;
关于ios - 代码在 iPhone 5s+ 上运行良好,而不是以前的版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32237900/