我正在开发AppleWatch应用程序。在我开发IOS应用程序最低版本IOS 6.0之前。 AppleWatch应用程序我正在使用WatchOS 2.0进行开发。 IOS应用程序类中的类代码。 WatchConnectivity框架和WCSessionDelegate协议需要min IOS 9.0版。那么如何在不崩溃的情况下运行旧版本
.h
#import <Foundation/Foundation.h>
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0
#import <WatchConnectivity/WatchConnectivity.h>
#endif
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0
@interface WatchConnectivityManager : NSObject<WCSessionDelegate>{
#else
@interface WatchConnectivityManager : NSObject{
#endif
}
@property(nonatomic, assign) BOOL oneTimeSaved;
+(WatchConnectivityManager*)getInstance;
-(void)sharedDefaultsDataSave:(NSString*)params;
@end
.m
#import "WatchConnectivityManager.h"
@implementation WatchConnectivityManager
@synthesize oneTimeSaved;
static WatchConnectivityManager *instance =nil;
- (id) init
{
/* first initialize the base class */
/* then initialize the instance variables */
if (self = [super init]) {
#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_9_0
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0") && NSClassFromString(@"WCSession")!=nil && [WCSession isSupported]) {
WCSession *session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];
}
#endif
}
/* finally return the object */
return self;
}
@end
答案 0 :(得分:0)
#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_9_0
// after iPhone OS SDK 9.0
#else
// before iPhone OS SDK 9.0
#endif
你不能在iOS9.0之前使用WatchConnectivity框架和WCSessionDelegate协议。所以使用较低的API或什么都不做也会做同样的事情。
答案 1 :(得分:0)
您的Base SDK应该是iOS 9.0才能导入框架,而您可以将部署目标设置为低于9.0。它将构建您的项目,但显然您需要在调用WatchConnectivity
的任何方法之前检查可用性检查。