拓展不能直接引用項(xiàng)目中的第三方,這里以PureLayout為例
使用CocoaPods管理PureLayout
如果你創(chuàng)建了今日插件歇盼,在今日插件里面是不能直接引用PureLayout的舔痕,會(huì)提示not found豹缀。那你需要做一件事就是將這個(gè)PureLayout和你的今日插件的target關(guān)聯(lián)。
在項(xiàng)目中的Podfile文件中加入以下代碼:
target 'TodayWidget' do
pod 'PureLayout'
end
這個(gè)時(shí)候編譯以下項(xiàng)目會(huì)出現(xiàn)這個(gè)問(wèn)題
'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.
當(dāng)出現(xiàn)這個(gè)問(wèn)題的時(shí)候是需要處理以下宏定義PURELAYOUT_APP_EXTENSIONS
邢笙,以防止不可用的API的使用。
在Podfile里面加如下代碼:
target 'TodayWidget' do
pod 'PureLayout'
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? "PureLayout"
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)', 'PURELAYOUT_APP_EXTENSIONS=1']
end
end
end
end
end
end
其實(shí)原本這樣就已經(jīng)解決了問(wèn)題氮惯,但是,我在使用過(guò)程中并沒(méi)有達(dá)到預(yù)期效果妇汗,上述提示錯(cuò)誤任然存在帘不,那么我只好手動(dòng)去處理宏定義
處理宏定義1.png
然后再次編譯,問(wèn)題就解決了杨箭。
將源代碼直接集成到項(xiàng)目中
這個(gè)就很簡(jiǎn)單了寞焙,直接將源代碼放到TodayWidget文件夾下。此時(shí)依然會(huì)有上述錯(cuò)誤提示互婿,這個(gè)時(shí)候也是需要手動(dòng)去處理宏定義
處理宏定義2.png
和上圖一樣加上PURELAYOUT_APP_EXTENSIONS=1
就ok了捣郊。