-
Notifications
You must be signed in to change notification settings - Fork 550
App Extensions
Clement T edited this page Oct 15, 2015
·
1 revision
When using CTAssetsPickerController in an App Extension, please define preprocessor macro CT_APP_EXTENSIONS
to avoid using unavailable APIs.
If you do not do this, you will see an error such as:
'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.
Use a post_install
hook to have the preprocessor macro automatically added every time you run pod install
.
At the end of your Podfile
, add the following post_install
hook:
post_install do |installer|
# NOTE: If you are using a CocoaPods version prior to 0.38, replace `pods_project` with `project` on the below line
installer.pods_project.targets.each do |target|
if target.name.end_with? "CTAssetsPickerController"
target.build_configurations.each do |build_configuration|
if build_configuration.build_settings['APPLICATION_EXTENSION_API_ONLY'] == 'YES'
build_configuration.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = ['$(inherited)', 'CT_APP_EXTENSIONS=1']
end
end
end
end
end
The above post_install
hook will define the macro CT_APP_EXTENSIONS=1
for every build configuration on all CTAssetsPickerController
targets in the generated Pods
project that are used by App Extensions.
- In Xcode, click on your Project
- Click on the Target for your App Extension
- Click Build Settings
- Find (or search) Preprocessor Macros under
Apple LLVM 6.0 - Preprocessing
- For all build configurations (Debug & Release) add the macro:
CT_APP_EXTENSIONS=1
Now, when your App Extension target is selected, CTAssetsPickerController will not use unavailable APIs.