ios - 应用商店内产品 View ,不适用于 IOS 5,如何测试?

标签 ios objective-c cocoa-touch methods

我正在使用新的 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/

相关文章:

iphone - Telnet Iphone 开发

iphone - UIActivityViewController 有错误的按钮标题颜色

objective-c - "NSSet allObjects"是否随机排序?

ios - 用 UINavigationController 中的另一个 View 正确替换顶 View

swift - 使用 UITableViewRowAction 执行 segue 控制

ios - 从剪贴板粘贴不适用于 iOS 模拟器上的 React Native

html - 在 xcode 中的应用程序上运行网站并收到错误 "Thread 1: signal SIGABRT"

html - 如何在将 enml 转换为 html 时将 en-media 转换为 img

ios - AVAssetWriter 未知错误

objective-c - Cocoa 内存问题,从数组中删除对象时内存不会被回收