0

I have an app in the App Store whose minimum supported version is iOS 7.1.

For the next version, I've enhanced it to use the Photos framework, which was introduced in iOS 8.

In the code for the next version of the app, I've ensured that if it's running on an iOS 7 device, the new functionality is hidden.

However, when I try and run the app on my iOS 7.1 test device, it fails because I've included the Photos framework in a number of the classes, using:

#import <Photos/Photos.h>

The error I receive in Xcode is:

"dyld: Library not loaded: /System/Library/Frameworks/Photos.framework/Photos Referenced from: /var/mobile/Applications/2CA13C9B-EABC-47C3-A198-A7C703EACD59/ABCapp.app/ABCapp Reason: image not found"

Is there any way to do this at run time rather than compile time to ensure that I can still support iOS 7?

Thanks.

MattOhMatt
  • 53
  • 6
  • 1
    The `#import` statement will not cause any issue at runtime. That's not your issue. 1) Update your question with details about the crash. 2) Be sure you read the "SDK Compatibility Guide" in the iOS docs for details on how to do what you want. – rmaddy Oct 05 '15 at 20:31
  • See http://stackoverflow.com/questions/14002304/how-to-import-social-framework-only-for-ios-6 for an example of what to do. – rmaddy Oct 05 '15 at 20:40
  • Thanks @rmaddy I've added more detail above. It looks like I need to do weak linking of the entire Photos framework, not just a class. .. trying to find the correct syntax now. – MattOhMatt Oct 05 '15 at 21:09
  • You didn't make the framework optional. – rmaddy Oct 05 '15 at 21:14
  • That did the trick, thanks @rmaddy. – MattOhMatt Oct 05 '15 at 21:48

1 Answers1

0

Use framework weak linking.

When a symbol in a framework is defined as weakly linked, the symbol does not have to be present at runtime for a process to continue running. The static linker identifies a weakly linked symbol as such in any code module that references the symbol. The dynamic linker uses this same information at runtime to determine whether a process can continue running. If a weakly linked symbol is not present in the framework, the code module can continue to run as long as it does not reference the symbol.

And here's Marco Arment take on weak linking:

If you wanted your iPhone or iPad app to work with older versions of the OS, or if you wanted to make a universal app that ran on both iPhone and iPad, you need to ensure that the code never tries to call a method or instantiate an object that doesn’t exist on its OS. [...] The other option to avoid all of that is weak-linking, which makes the runtime manually look up the existence of every symbol before its first use.

Guillaume Algis
  • 10,705
  • 6
  • 44
  • 72
  • This is an iOS question. You should link to iOS docs, not Mac docs. – rmaddy Oct 05 '15 at 20:41
  • @rmaddy just figured it's the exact same content, but in the "iOS Developer Library". Heh, I don't think Apple bothered to adapt the document for iOS devs :/ – Guillaume Algis Oct 05 '15 at 20:53
  • Thanks @GuillaumeAlgis, it looks like what I need to do is weak linking of the entire Photos framework, although I'm struggling to find an example of the correct syntax. `#import -weak_framework ` isn't working and the Apple docs aren't very clear. Searching now, but if you happen to know it, that would be super helpful, thanks. – MattOhMatt Oct 05 '15 at 21:08
  • `-weak_framework` is a clang flag, not an `#import` argument. See https://stackoverflow.com/questions/6480765/how-do-i-weak-link-frameworks-on-xcode-4 . But I'd recommend continuing your search, it's always good to understand what you do :) – Guillaume Algis Oct 05 '15 at 21:15
  • 1
    Thanks @GuillaumeAlgis, weak linking to the entire framework was the answer. What had confused me was that I hadn't included the Photos framework in the project target, I'd just included it in the code. Once I added it to the target and made it optional, as per rmaddy's suggestion it worked fine. Thanks! – MattOhMatt Oct 05 '15 at 21:51