У меня проблема с расширением службы уведомлений. Я выполнил следующие этапы:Устранение проблемы с расширением уведомлений Xamarin
Чтобы реализовать, я сделал так.
- Добавлено Notification Service Extension с таким же префиксом мое приложение (добавление суффикса, например: APP: com.testapp.main - EXT: com.testapp.main.notificationextension)
- Создан APPID идентификатор com.testapp .main.notificationextension в центр членов компании Apple
- создал сертификат и профиля обеспечения для отправки толчок уведомления для APP ID com.testapp.main.notificationextension
- Импортируется в Xcode и Xamarin сертификат и инициализации
- построить мое приложение со ссылкой к уведомлению Exte ссылка.
- создал архив для того, чтобы TestFlight
- Подпись приложения с сертификатом распределения и Provisioning Profile
- Подпись расширение с сертификатом распределения и Provisioning Profile
- Загрузил в TestFlight
- Скачать и позволил толчок уведомление для моего приложения
- Отправленный богатый push-уведомление с помощью Localitics Dashboard для обмена сообщениями - Устройство получает push-уведомление , но не проходит для NotificationService.cs c ode расширения службы уведомлений!
Это мой NotificationService код:
using System;
using Foundation;
using UserNotifications;
namespace NotificationServiceExtension
{
[Register("NotificationService")]
public class NotificationService : UNNotificationServiceExtension
{
Action<UNNotificationContent> ContentHandler { get; set; }
UNMutableNotificationContent BestAttemptContent { get; set; }
const string ATTACHMENT_IMAGE_KEY = "ll_attachment_url";
const string ATTACHMENT_TYPE_KEY = "ll_attachment_type";
const string ATTACHMENT_FILE_NAME = "-localytics-rich-push-attachment.";
protected NotificationService(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public override void DidReceiveNotificationRequest(UNNotificationRequest request, Action<UNNotificationContent> contentHandler)
{
System.Diagnostics.Debug.WriteLine("Notification Service DidReceiveNotificationRequest");
ContentHandler = contentHandler;
BestAttemptContent = (UNMutableNotificationContent)request.Content.MutableCopy();
if (BestAttemptContent != null)
{
string imageURL = null;
string imageType = null;
if (BestAttemptContent.UserInfo.ContainsKey(new NSString(ATTACHMENT_IMAGE_KEY)))
{
imageURL = BestAttemptContent.UserInfo.ValueForKey(new NSString(ATTACHMENT_IMAGE_KEY)).ToString();
}
if (BestAttemptContent.UserInfo.ContainsKey(new NSString(ATTACHMENT_TYPE_KEY)))
{
imageType = BestAttemptContent.UserInfo.ValueForKey(new NSString(ATTACHMENT_TYPE_KEY)).ToString();
}
if (imageURL == null || imageType == null)
{
ContentHandler(BestAttemptContent);
return;
}
var url = NSUrl.FromString(imageURL);
var task = NSUrlSession.SharedSession.CreateDownloadTask(url, (tempFile, response, error) =>
{
if (error != null)
{
ContentHandler(BestAttemptContent);
return;
}
if (tempFile == null)
{
ContentHandler(BestAttemptContent);
return;
}
var cache = NSSearchPath.GetDirectories(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomain.User, true);
var cachesFolder = cache[0];
var guid = NSProcessInfo.ProcessInfo.GloballyUniqueString;
var fileName = guid + ATTACHMENT_FILE_NAME + imageType;
var cacheFile = cachesFolder + fileName;
var attachmentURL = NSUrl.CreateFileUrl(cacheFile, false, null);
NSError err = null;
NSFileManager.DefaultManager.Move(tempFile, attachmentURL, out err);
if (err != null)
{
ContentHandler(BestAttemptContent);
return;
}
UNNotificationAttachmentOptions options = null;
var attachment = UNNotificationAttachment.FromIdentifier("localytics-rich-push-attachment", attachmentURL, options, out err);
if (attachment != null)
{
BestAttemptContent.Attachments = new UNNotificationAttachment[] { attachment };
}
ContentHandler(BestAttemptContent);
return;
});
task.Resume();
}
else {
ContentHandler(BestAttemptContent);
}
}
public override void TimeWillExpire()
{
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
ContentHandler(BestAttemptContent);
return;
}
}
}
Итак, в чем проблема? – Demitrian
Устройство получает push-уведомление, но не передает код NotificationService.cs службы уведомлений! –
Что значит «не проходит»? Вы имеете в виду, что 'DidReceiveNotificationRequest' не выполняется? – Demitrian