How to use iOS network extensions for local push connectivity on Xamarin?

Jose Vega 1 Reputation point
2022-01-18T18:15:42.74+00:00

Our project uses iOS local push connectivity to support local push notifications. We tried to add an a network extension with such capabilities and we didn't find a way from the standard Xamarin UI to do that.

So we created another extension and manually set the values on the entitlements and plist to match the network extension with local push connectivity that we need.

On the extension plist...

<key>NSExtension</key>
<dict>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.networkextension.app-push</string>
    <key>NSExtensionPrincipalClass</key>
    <string>LocalPushDemo</string>
</dict>

Our principal class extends from NEAppPushProvider (seems to be ported) and the project compiles successfully

using System;
using System.Threading.Tasks;
using Foundation;
using NetworkExtension;

namespace LocalPushDemo
{
    [Register("LocalPushDemo")]
    public class LocalPushDemo : NEAppPushProvider

We have the right provisioning profiles (since we can run an example using a native app). But when we run the app on Xamarin it crashes after the splash screen.

Last error I see on console is:
FBSceneManager/sceneID:com.krasamo.rauland.staffapp-default update failed: <NSError: 0x28348e9d0; domain: FBSceneErrorDomain; code: 1 (operation-failed); reason: "Scene update failed."> {
NSUnderlyingError = <NSError: 0x28341cc60; domain: BSServiceConnectionErrorDomain; code: 3 (OperationFailed); reason: "XPC error received on message reply handler">;
}

Is it possible to configure a Xamarin project to use local push connectivity?

Developer technologies .NET Xamarin
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2022-01-19T07:00:37.367+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    To implement the push notification in a Xamarin.iOS app, I'm afraid you have to create a Notification Service Extension instead of network extension, then handle the DidReceiveNotificationRequest method.

    The error is thrown by FBSceneManager, and is related to the environment. After iOS 10, the developer must inform the OS what environment Push Notification are running in as either development or production. You could open Entitlements.plist file, check aps-environment, refer to https://learn.microsoft.com/en-us/xamarin/ios/platform/user-notifications/enhanced-user-notifications?tabs=windows#configuring-the-remote-notifications-environment

    There is also a simple, you could refer to https://github.com/xamarin/ios-samples/tree/56aa9e2ea1e5e6236b588e37223a78539f7c9477/ios10/MonkeyNotify

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.