2016-01-21 44 views
1

我正在開發一個AppleWatch應用程序。在開發IOS應用程序min版本IOS 6.0之前。我正在使用WatchOS 2.0開發AppleWatch應用程序。 IOS應用程序類下的類代碼。 WatchConnectivity框架和WCSessionDelegate協議需要min IOS版本9.0。那麼,如何運行老版本沒有崩潰IOS協議和框架最低IOS版本檢查

.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
#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_9_0 
    // after iPhone OS SDK 9.0 
#else 
    // before iPhone OS SDK 9.0 
#endif 

不能使用WatchConnectivity框架和WCSessionDelegate協議iOS9.0.So之前做同樣的事情通過使用較低的API或者什麼都不做。

+0

更新我的問題你是怎麼說的。但我不能調試.m文件代碼 – hiwordls

0

您的Base SDK應該是iOS 9.0才能導入框架,而您可以將部署目標設置爲9.0以下。它會構建您的項目,但顯然您需要在調用WatchConnectivity的任何方法之前檢查可用性檢查。