16

I have a app with the minimum iOS target iOS7.

I am considering in add some extra features with the apple watch. Theres is any option to maintain the iOS7 as the minimum target and still add support for apple watch if the app is running on a iOS 8? Something like the extensions/widgets of the iOS8.

Thanks in advance

DaSilva
  • 1,358
  • 1
  • 19
  • 42

3 Answers3

12

You can set your deployment target to iOS7.x and make sure you build against iOS8.2 SDK. You will need to set the frameworks as optional (weak linking) in your build settings and perform run time checks to ensure you don't attempt anything with them on an iOS7.x device.

Optional frameworks will resolve as nil in an app where the framework is not linked.

Tim
  • 8,932
  • 4
  • 43
  • 64
  • Transis for the help. Just one doubt, how can i validate the imports? – DaSilva Dec 16 '14 at 22:00
  • What do you mean by validate the imports? – Tim Dec 16 '14 at 23:12
  • for example, i have a class that is only compatible with iOS8. So when the app is running i validate if the class exist "if ([Example class])". The import should be added (#import Example.h), it will not give me a error when i am running in the iOS7, since the class is not available? – DaSilva Dec 16 '14 at 23:17
  • 2
    It will still compile as you will be building against the 8.x SDK, but when the app runs on your minimum deployment targets, any classes that are part of frameworks that aren't linked will just be considered nil, and sending messages to nil in Objective-c is completely valid. In a lot of scenarios, you won't even need to add if ([Example class]), because it will resolve to nil anyway. Just make sure you don't send any selectors to objects that don't respond to them, e.g. when a new API was added to an existing framework in both iOS7 and 8. Hope this helps. – Tim Dec 17 '14 at 10:45
  • Problem is that the embedded library (for the watchApp) can't be weak linked. So it's not gonna work. Is there any workaround? – Idan Feb 13 '15 at 13:32
3

Yes, it's possible by weak linking WatchKit and performing runtime checks if required classes are available. Check this out on Raywenderlich.

Mohsin Khubaib Ahmed
  • 1,008
  • 16
  • 32
arr80
  • 49
  • 1
  • 4
    It doesn't matter if it's WatchKit or any other new API. Weaklinking + runtime checks would allow OP to implement the WatchKit API, while keeping iOS7 as the base version. – Andrew Dec 16 '14 at 17:25
  • @Andrew I stand corrected, you're right. I assumed the `respondsToSelector` would fail. Good call. – JAL Dec 16 '14 at 17:27
0

In my case the only thing I had to do was creating the extension with Objective-C (Swift is not allowed on some iOS versions) and downgrading the Extension app target version to 8.2 instead of 8.3.