事事无绝对,只怕有心人。没有解决不了的问题,不放弃,总是会解决的。
记录在开发过程中遇到的问题
今天已经圆满完成一个 appClips 的上线,在开发和上线过程中,记录了一些遇到的问题,以及如何解决。先放出来,给到需要的人,毕竟到处找解决的问题,也是费时不少。
下面的问题,可能记录的不全面,你在开发过程中遇到了什么问题,给我留言,看到后会给你解答。
问题1
新创建的的 clips,使用系统默认的启动页时,走的是 Main.storeboard 文件。在 application 中自定义设置也是无效的。如下代码,设置是无效的。
let homeNav = BaseNavigationController.init(rootViewController: type.init())
window?.rootViewController = homeNav
window?.makeKeyAndVisible()
如果想要上面的代码生效,需要在 info.plist 文件中删除 Application Scene Manifest
选项中的内容。
问题2
在 clips 中使用主项目的代码时,可以需要引入主项目中引入的第三方依赖。这时,需要在 Podfile 文件中设置 clips target 下的依赖,比如下:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target 'MW_APP_Swift' do
platform :ios, '10.0'
pod 'Alamofire'
end
target 'MW_APP_Clip' do
platform :ios, '14.0'
pod 'Alamofire'
end
文件中可以看到,Podfile 中的依赖是根据 target 走的,也就是在不同的 target 下,可以设置不同的依赖。
问题2-跟进
如何 Proflie 上的内容设置成如上,则会在编译的时候有一个 Warning,并在后面的 Archive 的时候报错,如下:
Xcode warning: Multiple targets match implicit dependency for product
实际的问题就是每一个 target 下设置了 platform,导致依赖的包都有两个不同的 platform。正确的处理方式,如下:
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
platform :ios, '13.0'
abstract_target 'abstract_pod' do
pod 'Alamofire'
pod 'SwiftyJSON'
target 'MW_APP_Swift' do
end
target 'MW_APP_Clip' do
end
end
就是 platform
设置成一个。abstract_target
是设置抽象 target。所以 abstract_pod
也是可以随便写。
Podfile 中可以设置多个 target 的依赖,参考链接如下所示:
iOS - 一个工程多个target引入CocoaPods的方式_九楼的博客-优快云博客
问题 3
当运行 clips 的时候,可能会遇到 Unable to install "MW_APP_Clip
的提示。当查看详情的时候,会发现这样一段话:
Unable to install "MW_APP_Clip"
Domain: com.apple.dt.MobileDeviceErrorDomain
Code: -402620375
User Info: {
DVTErrorCreationDateKey = "2022-04-20 07:02:30 +0000";
IDERunOperationFailingWorker = IDEInstalliPhoneLauncher;
}
--
The code signature version is no longer supported.
Domain: com.apple.dt.MobileDeviceErrorDomain
Code: -402620375
遇到这个问题,就要找到对应的 target,在 General
菜单中,下拉找到 Frameworks、Libraries...
。先排查这里的 framework 都是需要的吗?把不需要的删除,然后看 Embeb
列中,选择 Do not Embed
。
问题4
如果主项目中有 MyProject-Bridging-Header.h
头文件时,在 Clip 的 target 中如何设置?
到主项目中的 Build Setting 中搜索 Bridging,会在搜索结果中看到主项目引用该头文件的路径。接下来就是复制这个路径,然后将这个路径粘贴到 clip 的 target 中相同的问题中。
也可以在 AppClip 项目中创建一个新的文件,MyProjectClip-Bridging-Header.h
,然后在 AppClip 的 Build Setting 中找到 Bridging,填写路径。
问题 5
当在 clip 的 target 下对应的 Active Compilation Conditions
中添加 APPCLIP
后,就可以在代码中使用下面的宏来区分主项目和 clips 项目的代码。
#if !APPCLIP
// Code you don't want to use in your app clip.
#else
// Code your app clip may access.
#endif
如果设置之后没有作用,那么就看一下主项目中的 Active Compilation Conditions
中是不是也有 APPCLIP
? 如果有,就删除它。
问题 6
当 archive 完包含 app clip 的应用后,上传到 app store,会返回一个警告(错误):
ITMS-90876: Missing entitlement - This app contains an app clip. The entitlement 'com.apple.developer.associated-appclip-app-identifiers' should be present and include the value of the app clip's application identifier.
解决这个问题,就是在主 APP 的 .entitlement 文件中添加 ‘com.apple.developer.associated-appclip-app-identifiers’ 字段,并设置 clip 的 identifier:
<key>com.apple.developer.associated-appclip-app-identifiers</key>
<array>
<string>$(AppIdentifierPrefix)com.myproject.Clip</string>
</array>
之后再上传 app store 就不会再有这个警告了。
问题 7
接上面的问题 6,在主应用中添加权利字段之后,可能在主应用的 target 中的 Signing & Capabilities
页面中看到如下错误:
Provisioning profile "devxxx" doesn't match the entitlements file's value for the com.apple.developer.associated-appclip-app-identifiers entitlement.
如果出现这个错误,大致的原因就是 Identifiers
中没有勾选 On Demand Install Capable for App Clip Extensions
,如下图所示:
登录苹果开发者平台,选择 Certificates,Identifiers & Profiles
-> Identifiers
,选择对应的 identifiers,进入详情,找到上图的选项并勾选它。
然后到 Profiles 页面,重新更新一下开发和生产环境的 profile 文件。
问题 8
在构建版本页面,设置“编辑高级体验“时,设置的 url,绑定了唯一的 appId,无法在其他的 appId 中去设置”编辑高级体验“。如何解除绑定?
暂未解决
这个问题一定要重视,需要扫码触发 app clips,就必须要设置“编辑高级体验”。所以目前来说一个 url 只能唯一绑定一个 appId。所以在设置之前要慎重慎重再慎重。