Browse Source

add check if WCSession is supported

Tobias Conradi 10 years ago
parent
commit
fceba30ae1
3 changed files with 14 additions and 6 deletions
  1. 9 6
      Sources/VLCAppDelegate.m
  2. 1 0
      Sources/VLCWatchCommunication.h
  3. 4 0
      Sources/VLCWatchCommunication.m

+ 9 - 6
Sources/VLCAppDelegate.m

@@ -167,11 +167,12 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
         setupBlock();
     }
 
-    _watchCommunication = [VLCWatchCommunication sharedInstance];
-
-    // TODO: push DB changes instead
-//    [_watchCommunication startRelayingNotificationName:NSManagedObjectContextDidSaveNotification object:nil];
-    [_watchCommunication startRelayingNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:nil];
+    if ([VLCWatchCommunication isSupported]) {
+        _watchCommunication = [VLCWatchCommunication sharedInstance];
+        // TODO: push DB changes instead
+        //    [_watchCommunication startRelayingNotificationName:NSManagedObjectContextDidSaveNotification object:nil];
+        [_watchCommunication startRelayingNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:nil];
+    }
 
     return YES;
 }
@@ -437,7 +438,9 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
 handleWatchKitExtensionRequest:(NSDictionary *)userInfo
               reply:(void (^)(NSDictionary *))reply
 {
-    [self.watchCommunication session:[WCSession defaultSession] didReceiveMessage:userInfo replyHandler:reply];
+    if ([VLCWatchCommunication isSupported]) {
+        [self.watchCommunication session:[WCSession defaultSession] didReceiveMessage:userInfo replyHandler:reply];
+    }
 }
 
 

+ 1 - 0
Sources/VLCWatchCommunication.h

@@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface VLCWatchCommunication : NSObject <WCSessionDelegate>
 
++ (BOOL)isSupported;
 + (instancetype)sharedInstance;
 
 - (void)startRelayingNotificationName:(nullable NSString *)name object:(nullable id)object;

+ 4 - 0
Sources/VLCWatchCommunication.m

@@ -18,6 +18,10 @@
 
 @implementation VLCWatchCommunication
 
++ (BOOL)isSupported {
+    return [WCSession class] != nil && [WCSession isSupported];
+}
+
 - (instancetype)init
 {
     self = [super init];