Version: 2017.2

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 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('-', '%'); new WWW("http:/example.com?token=" + hexToken); tokenSent = true; } } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961