Version: 2017.2 (switch to 2017.3b)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

NotificationServices.RegisterForNotifications

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static method RegisterForNotifications(notificationTypes: iOS.NotificationType): void;
public static void RegisterForNotifications(iOS.NotificationType notificationTypes);
public static method RegisterForNotifications(notificationTypes: iOS.NotificationType, registerForRemote: bool): void;
public static void RegisterForNotifications(iOS.NotificationType notificationTypes, bool registerForRemote);

Parameters

notificationTypes Notification types to register for.
registerForRemote Specify true to also register for remote notifications.

Description

Register to receive local and remote notifications of the specified types from a provider via Apple Push Service.

After an application registers for the specified remote notification types, the device token is received from Apple Push Service and is available via NotificationServices.deviceToken.

#pragma strict

public class NotificationRegistrationExample { var tokenSent;

function Start() { tokenSent = false; iOS.NotificationServices.RegisterForNotifications( iOS.NotificationType.Alert | iOS.NotificationType.Badge | iOS.NotificationType.Sound); }

function Update() { if (!tokenSent) { var token = iOS.NotificationServices.deviceToken; if (token != null) { // send token to a provider var hexToken = "%" + System.BitConverter.ToString(token).Replace('-', '%'); new WWW("http:/example.com?token=" + hexToken); tokenSent = true; } } } }
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; } } } }

Did you find this page useful? Please give it a rating: