【问题标题】:Unable to configure the NEAppPushManager for Local Push Connectivity无法为本地推送连接配置 NEAppPushManager
【发布时间】:2021-07-10 10:01:11
【问题描述】:

我正在尝试配置我的应用程序以使用 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 的这个特殊功能吗?

【问题讨论】:

  • 您是否尝试在您的应用功能中添加“WiFi信息访问”?
  • @DimaRostopira 刚刚添加,但没有任何改变。
  • 你解决了吗?
  • @MERN 部分.. 我们发现它是使用生成的证书对应用程序进行基本签名。证书不能是 xcode 自动生成的,必须使用通常的苹果开发者门户生成。

标签: ios swift apple-push-notifications apple-local-push-connectivity


【解决方案1】:

根据苹果的Local Push Connectivity page

要使用本地推送连接 API,您的应用必须具有带有 app-push-provider 值的 Network Extensions Entitlement。从Entitlement Request Page 请求此权利。收到授权后,将其应用于您的应用程序目标和提供程序扩展目标。

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

【讨论】:

    猜你喜欢
    • 2014-04-17
    • 1970-01-01
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多