iProgrammer Tip #6: “Weak linking” additional libraries
Sure, first time when i learnt about frameworks, i was really excited! What interested me most was, a framework can be marked as “Weak” so that applications can still work using new features in new framework and when using old version of the framework,can ignore some functionality. But as much as i was excited, i didn’t know how to mark a framework as “Weak”.
for instance, I was trying to support Compose Mail from within my application and while going through instructions below:
3. Make MessageUI a weak framework (set its role to Weak) An application will fail to launch or proceed if it attempts to load a framework on devices where this framework is absent. With weak linking, an application does not fail, but proceeds when a symbol or framework is not present at runtime. All weak-linked symbols are set to NULL on devices without them. To designate MessageUI as weak-linked, select the target's Link Binary With Libraries build phase, then change MessageUI's role from Required to Weak in the detail view.
Sounds simple, but for some reason i couldn’t figure out immediately how to do that. Maybe its common knowledge?
But for those who dont know this, here’s a tip to get this done:
To add new framework:
- select the Target and select the application name and pull down (either -> arrow or click on that arrow symbol)
- select Link Binary With Libraries
- Right click and select Add
- Choose Existing frameworks
- Then click on the + in the next screen
- Depends on your target SDK, you will get the option to choose the additional frameworks. For 3.0 it looks like below
- After adding the framework, you can select the “Type” on the right and change to “Weak”
Then Build as usual.
Important to note:
Check for the existence of APIs before calling them
and
Provide a workaround for non-existent APIs
Leave a Reply
You must be logged in to post a comment.



