拓展不能直接引用项目中的第三方,这里以PureLayout为例
使用CocoaPods管理PureLayout
如果你创建了今日插件,在今日插件里面是不能直接引用PureLayout的,会提示not found。那你需要做一件事就是将这个PureLayout和你的今日插件的target关联。
在项目中的Podfile文件中加入以下代码:
target 'TodayWidget' do
pod 'PureLayout'
end
这个时候编译以下项目会出现这个问题
'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.
当出现这个问题的时候是需要处理以下宏定义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
其实原本这样就已经解决了问题,但是,我在使用过程中并没有达到预期效果,上述提示错误任然存在,那么我只好手动去处理宏定义
然后再次编译,问题就解决了。
将源代码直接集成到项目中
这个就很简单了,直接将源代码放到TodayWidget文件夹下。此时依然会有上述错误提示,这个时候也是需要手动去处理宏定义
和上图一样加上PURELAYOUT_APP_EXTENSIONS=1
就ok了。