简体   繁体   English

在iOS通知屏幕Xamarin中显示通知的格式

[英]Format display of notification in ios notification screen xamarin

Is there a way to change how the text is displayed in notification area on ios >10? 是否可以更改ios> 10上通知区域中文本的显示方式?

For example, currently I am sending json string as the notification that contains the necessary info for the app, and in the notification area on the lock screen or pull down menu it is displaying that json string. 例如,当前我正在发送json字符串作为包含应用程序必要信息的通知,并且在锁定屏幕或下拉菜单的通知区域中显示该json字符串。 Is there a way to customize the text that gets displayed there? 有没有一种方法可以自定义在那里显示的文本?

I have searched around, but the things I have found have not helped. 我四处搜寻,但是发现的东西并没有帮助。 I can handle the display of the notification when the app is in the foreground. 当应用程序处于前台时,我可以处理通知的显示。

If it is not directly possible, would sending the notification as a silent one and then pushing a formatted notification to ios notification area be possible? 如果不可能直接发送,是否可以将通知以静默方式发送,然后将格式化的通知推送到ios通知区域?

My template for reference: 我的模板供参考:

const string templateBodyAPNS = "{\"aps\":{\"alert\":\"$(messageParam)\", \"category\": \"test\"}}";

I have tried with mutable content 1, also didnt work. 我尝试了可变内容1,也没用。

The code of my extension: 我的扩展代码:

using System;
using UIKit;
using UserNotifications;
using UserNotificationsUI;

namespace NotificationContentExtension
{
    public partial class NotificationViewController : UIViewController, IUNNotificationContentExtension
    {
        protected NotificationViewController(IntPtr handle) : base(handle)
        {
            // Note: this .ctor should not contain any initialization logic.
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Do any required interface initialization here.
        }

        public void DidReceiveNotification(UNNotification notification)
        {
            label.Text = "Hello";
            new UIAlertView("Received", "Working", null, "Ok").Show();
        }
    }
}

You need to add a Notification Service Extension to your Xamarin.iOS project in order to customize the way the push notification is presented. 您需要向Xamarin.iOS项目添加Notification Service Extension ,以便自定义推送通知的显示方式。

1.In Visual Studio go to File/new Project/Visual C#/iOS Exensions/Notification Service Extension. 1.在Visual Studio中,转到“文件/新项目/ Visual C#/ iOS扩展/通知服务扩展”。

  1. The Notification Service must have a bundle name that has the iOS project as the prefix: Notification Service必须具有以iOS项目作为前缀的捆绑软件名称:

    iOS project bundle id: www.companyname.iosappname iOS专案套件编号:www.companyname.iosappname

    Extension bundle id: www.companyname.iosappname.extensionname 扩展束ID:www.companyname.iosappname.extensionname

  2. Need to add a reference to the iOS project that points to the extension. 需要添加对指向扩展的iOS项目的引用。 So right click on the iOS project, add reference and select the extension project. 因此,右键单击iOS项目,添加参考并选择扩展项目。

  3. Currently in Visual Studio after you add the Extension reference to the iOS project you will only be able to run the iOS project in Release mode, not in Debug mode. 当前在Visual Studio中,将扩展引用添加到iOS项目后,您将只能在发布模式下运行iOS项目,而不能在调试模式下运行。 If you try in Debug mode you will get an error. 如果在“调试”模式下尝试,则会出现错误。 To run in debug mode, remove the Extension reference first from the iOS Project. 要以调试模式运行,请首先从iOS项目中删除扩展参考。

  4. You need to change the APNS format to: 您需要将APNS格式更改为:

    const string templateBodyAPNS = @"{ ""aps"" : { ""alert"" : ""$(messageParam)"", ""mutable-content"": 1 }, }"; const string templateBodyAPNS = @“ {”“ aps”“:{”“ alert”“:”“ $(messageParam)”“,”“ mutable-content”“:1},}”;

    Adding "mutable-content":1 signals that a Notification Service will intercept the push notification. 添加“ mutable-content”:1表示Notification Service将拦截推送通知。

  5. The Notification Service Extension cannot exchange data with the main iOS project. Notification Service Extension无法与主iOS项目交换数据。 In order to share data between the two you will need to create an App Group on the Apple Developer website. 为了在两者之间共享数据 ,您将需要在Apple Developer网站上创建一个应用程序组 Make sure you add the app group to both projects in their Entitlements.plist files and also on the Apple Developer Website. 确保将应用程序组添加到两个项目的Entitlements.plist文件中,以及Apple Developer网站上。

  6. You need to activate push notifications on the Apple Developer Website for both your project and the Notification Service Extension and also create certificates and provisioning profiles for both. 您需要在Apple Developer网站上为项目和Notification Service Extension激活推送通知,还需要为两者创建证书和供应配置文件。

  7. Only publish the iOS Project, the Extension is automatically included. 仅发布iOS项目,该扩展会自动包含在内。

Let me know if you have any more questions. 如果您还有其他问题,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 吐司通知Xamarin iOS - Toast notification Xamarin iOS Xamarin iOS 中的可操作推送通知 - Actionable push notification in Xamarin iOS 检查是否授予通知权限(Xamarin,iOS) - Check if notification permission got granted (Xamarin, iOS) 如何在Xamarin的本地通知中显示应用名称? - How to display the app name in a local notification in Xamarin? 如何在xamarin.android中启用浮动通知和锁屏通知(Java或Kotlin都可以) - how to enable floating notification and lock screen notification in xamarin android(Java or Kotlin is okay) Xamarin C#中IOS应用上的FCM背景通知不起作用 - FCM Background Notification on IOS app in Xamarin C# not working Asp.net核心推送通知到Xamarin(Android,IOS) - Asp.net core push notification to Xamarin (Android, IOS) 打开铃声选择器以选择iOS中的通知声音(Xamarin Forms) - Open a Ringtone Picker to select Notification sound in iOS (Xamarin Forms) XAMARIN - Firebase Cloud Messaging - Android 设备不显示通知但他收到通知 - XAMARIN - Firebase Cloud Messaging - Android Device not display notification but he receives it Xamarin表单和远程通知 - Xamarin Forms and Remote Notification
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM