我正在开发 AppleWatch 应用程序。之前我开发了一个IOS应用最小版本IOS 6.0。我正在使用 WatchOS 2.0 开发的 AppleWatch 应用程序。下面是IOS应用程序类中的类代码。WatchConnectivity 框架和 WCSessionDelegate 协议需要最低 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