3

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?

Wang Liang
  • 4,244
  • 6
  • 22
  • 45
LucaRoverelli
  • 1,116
  • 1
  • 9
  • 15

1 Answers1

1

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.)

Eric Hedstrom
  • 1,627
  • 10
  • 13
  • NEAppPushProvider is always active for me, i do all configuration, :( i'm really lost – tamtoum1987 May 04 '23 at 03:25
  • 1
    @tamtoum1987 Do you mean always inactive? Do you get an error from `saveToPreferences` like the OP did, or something else? Along with everything the OP mentioned, also verify your entitlements files for the main app and extension. If still having problems, open a new question here and/or on the Apple developer support forums. – Eric Hedstrom May 08 '23 at 20:43
  • Yes it is always inactive, i opened a new question here : https://stackoverflow.com/questions/76173951/local-push-notification-neapppushprovider-never-called. i put there more details – tamtoum1987 May 08 '23 at 21:31