我正在使用新的 API 来查看应用内应用商店产品。我知道它只能在 IOS 6 及更高版本上运行,但是,我的应用程序针对 ios 5 及更高版本。现在,当您点击要存储的按钮时,该应用程序将变得柠檬并卡住在您身上!
SKStoreProductViewController
如何测试该设备是否能够执行此功能?或者如果这是 ios 6 及更高版本?
我正在寻找类似于“应用内邮件”的东西,它有一个名为 CanSendMail
的方法,SKStore
有这样的方法吗?
此外
我将框架作为选项
弱链接。
UPADTE
我尝试使用这个,但仍然不起作用!没有任何记录:(
if (error) {
NSLog(@"Error %@ with User Info %@.", error, [error userInfo]);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Your device doesn't support In-App Product View"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
} else {
// Present Store Product View Controller
[self presentViewController:storeProductViewController animated:YES completion:nil];
}
}];
}
最佳答案
测试类在运行时是否可用的一般方法是使用 NSClassFromString
。所以,你可以这样做:
Class cls = NSClassFromString(@"SKStoreProductViewController");
if (cls)
{
// The device is iOS 6.0 or higher, so it's safe to use this class
SKStoreProductViewController *viewController = [[cls alloc] init];
...
}
else
{
// The device is pre-iOS 6.0; show an error message or have some other
// reasonable fallback behavior
}
如果您正在使用的框架在您所定位的最低版本的 iOS 中不可用,那么您还必须确保您弱链接该框架。正如 @rmaddy 指出的,您应该看到 SDK Compatibility GUide了解完整、血腥的细节。
关于ios - 应用商店内产品 View ,不适用于 IOS 5,如何测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16051538/