无法为本地推送连接配置NEAppPushManager



我正在尝试配置我的应用程序,以便使用;"本地推送连接";如WWDC 2020会话中所描述的。

我创建了我的应用程序和我的扩展程序;"网络扩展";权利

在我的扩展的Info.plist中,我添加了所需的配置:

<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.networkextension.app-push</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).PushProvider</string>
</dict>

我创建了如下扩展类:

class PushProvider: NEAppPushProvider {
...
}

现在,在AppDelegate中,我尝试按如下方式配置扩展:

let pushManager = NEAppPushManager()
pushManager.matchSSIDs = ["SSID Name"]
pushManager.localizedDescription = "PushProvider"
pushManager.providerBundleIdentifier = "---my-product.name----.PushProvider"
pushManager.delegate = self
pushManager.isEnabled = true
pushManager.providerConfiguration = [
"host": "192.168.1.94"
]
pushManager.saveToPreferences(completionHandler: { error in
print("error? (error)")
print("is active: (pushManager.isActive)")
})

saveToPreferences方法总是返回以下错误:

2021-04-15 12:39:59.416074+0200 PushTest[2452:411559] [] : Failed to get the configuration index while saving configuration PushProvider: Error Domain=NEConfigurationErrorDomain Code=10 "permission denied" UserInfo={NSLocalizedDescription=permission denied}
2021-04-15 12:39:59.416437+0200 PushTest[2452:411556] [] <NEAppPushManager: 0x283807e10>: Failed to save the configuration: Error Domain=NEConfigurationErrorDomain Code=10 "permission denied" UserInfo={NSLocalizedDescription=permission denied}
error? Optional(Error Domain=NEAppPushErrorDomain Code=3 "(null)")
is active: false

我不明白我的配置出了什么问题,因为我似乎遵循了配置的所有必要步骤。

有人使用过iOS的这个特殊功能吗?

根据苹果的本地推送连接页面,

若要使用本地推送连接API,您的应用程序必须具有app-Push-provider值的网络扩展权限。从授权请求页面请求此授权。收到授权后,将其应用于您的应用程序目标和提供商扩展目标。

根据我的经验,最后一步意味着使用上述权利,在您的Apple Developer帐户中手动创建应用程序和网络扩展的配置文件。然后下载配置文件并将其导入应用程序目标和本地推送网络扩展目标的Xcode中。(因此,关闭配置文件的自动Xcode管理。(

最新更新