Version: 2017.3

NotificationServices.RegisterForNotifications

切换到手册
public static void RegisterForNotifications (iOS.NotificationType notificationTypes);
public static void RegisterForNotifications (iOS.NotificationType notificationTypes, bool registerForRemote);

参数

notificationTypes 要注册的通知类型。
registerForRemote 指定 true 还将注册远程通知。

描述

注册以通过 Apple Push Service 从提供程序接收指定类型的本地和远程通知。

在应用程序注册指定的远程通知类型后,将从 Apple Push Service 接收设备令牌,并可通过 NotificationServices.deviceToken 获取。

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using NotificationServices = UnityEngine.iOS.NotificationServices;
using NotificationType = UnityEngine.iOS.NotificationType;

public class NotificationRegistrationExample : MonoBehaviour { bool tokenSent;

void Start() { tokenSent = false;

NotificationServices.RegisterForNotifications( NotificationType.Alert | NotificationType.Badge | NotificationType.Sound); }

void Update() { if (!tokenSent) { byte[] token = NotificationServices.deviceToken; if (token != null) { // send token to a provider string hexToken = "%" + System.BitConverter.ToString(token).Replace('-', '%'); UnityWebRequest.Get("http:/example.com?token=" + hexToken).SendWebRequest(); tokenSent = true; } } } }