1

I have added some watchOS 3 features to an existing watchOS 2 as I have to support both WatchOS 2 and WatchOS 3 devices so I need to check the function availability before it gets called. for example in ExtensionDelegate I have this function which only WatchOS 3 devices should call it, how can I check the WatchOS version in objective c.

-(void)applicationDidEnterBackground {

    [self scheduleRefreshBackgroundTask];

}  

I have read How to check iOS version? but I'm still confused how to check it in objective c.

Community
  • 1
  • 1
Samira
  • 215
  • 2
  • 14
  • that link has objective version too. What else do you need ? – Teja Nandamuri Jul 26 '16 at 14:58
  • I need to know the equivalent of this for WatchOS 3 and in objective c --> if #available(iOS 10, *) {} – Samira Jul 26 '16 at 15:15
  • http://stackoverflow.com/questions/32518548/swift-available-keyword-vs-respondstoselector – Teja Nandamuri Jul 26 '16 at 15:16
  • Thanks Teja, this one is in Swift too but I need it in Objectve c. It seems with Swift its so easy to check the API availability – Samira Jul 26 '16 at 15:20
  • There is no direct replacement of #Available in obj-c. The equivalent of #available in swift is to use instancesRespondToSelector in obj-c – Teja Nandamuri Jul 26 '16 at 15:21
  • based on the http://stackoverflow.com/questions/3339722/how-to-check-ios-version I don't know how to use [[NSProcessInfo processInfo] operatingSystemVersion] to compare the os version – Samira Jul 26 '16 at 15:32
  • Use [[NSProcessInfo processInfo]operatingSystemVersion] to get the string value of the OS version – Teja Nandamuri Jul 26 '16 at 15:37
  • but operatingSystemVersion doesn't return a string value. – Samira Jul 26 '16 at 15:46
  • Did you try it ? What does NSLog(@"%@",[[NSProcessInfo processInfo]operatingSystemVersion] ) gives you ? – Teja Nandamuri Jul 26 '16 at 15:47
  • I get EXC_BAD_ACCESS error and it's not compiled. – Samira Jul 26 '16 at 17:52
  • I'm sure that line will not cause a crash.Please post the crash stack trace, and also add some relevant code of what caused the crash. – Teja Nandamuri Jul 26 '16 at 17:53
  • the error message is: "Format specifies type 'id' but the argument has type 'NSOperatingSystemVersion' . I put the line of the code in ExtensionDelegate applicationDidBecomeActive – Samira Jul 26 '16 at 18:10

1 Answers1

1

I finally found out that by adding WK_AVAILABLE_WATCHOS_ONLY(3.0) I can control the watchOS versions when I need to add the watchOS 3 features to an existing watchOS 2 project and make them compatible:

- (void)applicationDidEnterBackground
{
   [self scheduleRefreshBackgroundTask];
} 

- (void)scheduleRefreshBackgroundTask WK_AVAILABLE_WATCHOS_ONLY(3.0)
{
    // do something
}
emotality
  • 12,795
  • 4
  • 39
  • 60
Samira
  • 215
  • 2
  • 14