Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking to a Embedded Framework from a app extension

I have a project with

  • one application target: MyApp
  • one Embedded Framework target: MyKit.framework
  • one application extension target: MyExtension

Here is a sample project.

I want to use the shared code of MyKit in the MyExtension but when I link it, I get the warning

ld: warning: linking against a dylib which is not safe for use in application extensions: /Users/me/Library/Developer/Xcode/DerivedData/MyApp-dnztzmxjghjlsteetlokzhjtjqkm/Build/Products/Debug-iphonesimulator/MyKit.framework/MyKit

Apple's documentation says

To configure an app extension target to use an embedded framework, set the target’s “Require Only App-Extension-Safe API” build setting to Yes. If you don’t, Xcode reminds you to do so by displaying the warning “linking against dylib not safe for use in application extensions”.

which is correctly set by default. I could get rid of the warning by setting "Require Only App-Extension-Safe API" to NO but this could lead to some app rejections.

The framework does not use any API not allowed in an app extension. In fact, in the sample project, you'll see that MyKit.framework only logs a message to a console.

What is a correct way to link to en embedded framework from an app extension to avoid this wrning?

like image 636
Jan Avatar asked Feb 21 '17 08:02

Jan


People also ask

What is an embedded framework?

A Real-Time Embedded Framework (RTEF) is an implementation of the Active Object design pattern specifically designed for real-time embedded systems. RTEF provides the event-driven infrastructure for executing Active Objects based on a real-time kernel (RTOS kernel) to ensure deterministic, real-time performance.

What is an app extension?

An app extension lets you extend custom functionality and content beyond your app and make it available to users while they're interacting with other apps or the system. You create an app extension to enable a specific task.


1 Answers

If your goal is to share code in between App and Extension, you do not need to create a Framework. You can add the source file to different targets:

To use a framework, set "Require Only App-Extension-Safe API" to YES in the framework target build settings. After doing so, there are no warnings in your sample project.


Opinion based addition: As you do not want to share code in between projects, using a frameworks does not make sense to me here. If you want to share the code in between projects and thus decide to use a framework, I recommend to make it an independent Xcode project under own version control.

like image 118
shallowThought Avatar answered Oct 26 '22 11:10

shallowThought