【问题标题】:In-App Store Product View, not working on IOS 5, how to test?In-App Store Product View,在IOS 5上不工作,如何测试?
【发布时间】:2013-04-09 17:07:32
【问题描述】:

我将新 API 用于应用内应用商店产品视图。我知道它应该只适用于 IOS 6 及更高版本,但是,我的应用程序是针对 ios 5 及更高版本的。现在,当您点击将您带到商店的按钮时,该应用程序将变得柠檬并冻结您!

SKStoreProductViewController

如何测试此设备是否能够执行此功能?或者如果这是 ios 6 及更高版本?

我正在寻找类似于“应用内邮件”的东西,它有一个名为CanSendMail 的方法,SKStore 有这样的方法吗?

另外

我将框架弱链接为Option

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];
    }
}];

}

【问题讨论】:

  • 您可以查看SDK Compatibility Guide,了解有关正确执行运行时检查的完整详细信息,例如此类。
  • @rmaddy 所以我知道这个类没有特殊的方法,比如CanSendMail in MailComposer?
  • 不,没有。我从来没有暗示有。即使有,它在 iOS 5.x 下也无用,因为直到 6.0 才添加该类。我提供的链接将帮助您正确使用您的应用支持的每个 iOS 版本中不存在的类、方法和框架。请参阅 Adam 的答案以正确检查 SKStoreProductViewController 类。

标签: ios objective-c cocoa-touch methods


【解决方案1】:

测试类在运行时是否可用的一般方法是使用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 以获得完整的血腥细节。

【讨论】:

  • 在过去,由于在对alloc 的调用中引用了类名,您仍然会遇到崩溃。这仍然是一个问题吗?我总是在从NSClassFromString 获得的Class 对象上调用alloc
  • @rmaddy:我认为你是对的,我对细节有点模糊,并根据记忆重建了我的示例。
  • 我应该把这个放在哪个方法下?
  • @AdamRosenfield,这是真的!当我使用与设置商店产品视图相同的方法时,我遇到了崩溃!
【解决方案2】:

我发现这个效果最好:

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {

// iOS Version 5.1 and older    

}

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {

// iOS Version 6.0 and later    

}

将您的商店产品视图代码复制到 6.0 之后的版本,并将您的后备代码复制到 5.1 和更早版本。

我从这里学到了这一点。祝你好运!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 2016-10-27
    • 2019-02-19
    • 2011-09-21
    相关资源
    最近更新 更多