這個會發生在 AFNetwork 用在 App Extension 時,在編譯時,會發生類似以下的錯誤訊息:
/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m:96:21:
'sharedApplication' is unavailable: not available on iOS (App Extension)
- Use view controller based solutions where appropriate instead.
解法很雜,有人說要在 Pods-xxx-AFNetworking 的 Preprocessor Macros 加上 AF_APP_EXTENSIONS=1 的參數
但單單這個又好像不太 WORK. 所以,也有這篇說要在 Podfile 加上以下這段 PostInstall Script
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
if target.name == "Pods-EMToday-AFNetworking" # EMToday should be the Extension target name
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'AF_APP_EXTENSIONS=1']
end
end
end
end
最後找到這篇,說明如下:
To remove sharedApplication issue from CocoaPods Libraries you just need to change Build Options within Build Settings for your pod.
Just type to search Require Only App-Extension-Safe API and then change the value to NO as it is on the image below:
將 Require Only App-Extension-Safe API 設成 NO,再加上以上(不確定,也許只要這個就可,以上的懶得清了...XDD),就解決掉這個問題
停留在 Cocoapods 0.35 好久,終於可以升到的 0.38 了.... >"<
Orignal From: Xcode7 and Cocoapods 0.38.2 之一些雜記