2013-04-17 29 views
2

我正在使用新的API进行应用内商店产品视图。我知道它应该只适用于IOS 6及更高版本,但是,我的应用程序针对iOS 5及更高版本。现在,当您按下需要存储的按钮时,应用程序将变为柠檬并冻结在您身上!应用商店产品视图,不适用于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]; 
    } 
}]; 

} 
+3

您可以参阅[SDK兼容性指南](https://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/cross_development/Introduction/Introduction.html#//apple_ref/doc/) uid/10000163i)以获取正确执行此类运行时检查的完整详细信息。 – rmaddy

+0

@rmaddy所以我明白这个类没有特殊的方法,例如'MailComposer'中的'CanSendMail'? – user1949873

+0

不,没有。我从来没有暗示过。即使有,在iOS 5.x下也没有用处,因为直到6.0版才加入类。我提供的链接将帮助您正确使用应用程序支持的每个iOS版本都不存在的类,方法和框架。请参阅Adam的回答以正确检查“SKStoreProductViewController”类。 – rmaddy

回答

1

我发现这个效果最好:

#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及以上。

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

+0

爱宏!作品完美无瑕!非常感谢你 – user1949873

2

检测的通用方式,如果一个类可以在运行时使用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的完整细节。

+0

在过去,由于在调用'alloc'时引用类名称,您仍然会崩溃。这仍然是一个问题吗?我总是从'NSClassFromString'获得的'Class'对象上调用'alloc'。 – rmaddy

+0

@rmaddy:我认为你是对的,我是在细节上有点模糊,并从内存中重建我的例子。 –

+0

我应该使用哪种方法? – user1949873

相关问题