I am trying to configure my app in order to use the "Local Push Connectivity" as depicted in the WWDC 2020 session.
I created my app and my extension, with the "Network Extension" Entitlement.
In the Info.plist of my extension, I've added the required configuration:
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.networkextension.app-push</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).PushProvider</string>
</dict>
And I have created the extension class as follow:
class PushProvider: NEAppPushProvider {
...
}
Now, in the AppDelegate
, I'm trying to configure the extension as follow:
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)")
})
The saveToPreferences
method always returns the following error:
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
I can't understand what is wrong with my configuration, since it seems that I follow all the necessary steps for the configuration.
Anyone has used this particular feature of iOS?
According to Apple's Local Push Connectivity page,
To use the Local Push Connectivity API, your app must have the Network Extensions Entitlement with the app-push-provider value. Request this entitlement from the Entitlement Request Page. After you receive the entitlement, apply it to both your app target and your provider extension target.
In my experience, that last step means manually creating provisioning profiles in your Apple Developer account for the app and the network extension, using the entitlement as mentioned. Then download the profiles and import them into Xcode for the app target and local push network extension target. (So, turn off automatic Xcode management of the profiles.)