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