Class AuthorizationRequest | Mobile Notifications | 1.1.0-preview
docs.unity3d.com
    Show / Hide Table of Contents

    Class AuthorizationRequest

    Use this to request authorization to interact with the user when you with to deliver local and remote notifications are delivered to the user's device.

    Inheritance
    Object
    AuthorizationRequest
    Namespace: Unity.Notifications.iOS
    Syntax
    public class AuthorizationRequest : IDisposable
    Remarks

    This method must be called before you attempt to schedule any local notifications. If "Request Authorization on App Launch" is enabled in "Edit -> Project Settings -> Mobile Notification Settings" this method will be called automatically when the app launches. You might call this method again to determine the current authorizations status or retrieve the DeviceToken for Push Notifications. However the UI system prompt will not be shown if the user has already granted or denied authorization for this app.

    Examples
    using (var req = new AuthorizationRequest(AuthorizationOption.Alert | AuthorizationOption.Badge, true))
    {
        while (!req.IsFinished)
        {
            yield return null;
        };
    
        string result = "\n RequestAuthorization: \n";
        result += "\n finished: " + req.IsFinished;
        result += "\n granted :  " + req.Granted;
        result += "\n error:  " + req.Error;
        result += "\n deviceToken:  " + req.DeviceToken;
        Debug.Log(res);
    }

    Constructors

    AuthorizationRequest(AuthorizationOption, Boolean)

    Initiate an authorization request.

    Declaration
    public AuthorizationRequest(AuthorizationOption authorizationOption, bool registerForRemoteNotifications)
    Parameters
    Type Name Description
    AuthorizationOption authorizationOption

    The authorization options your app is requesting. You may specify multiple options to request authorization for. Request only the authorization options that you plan to use.

    Boolean registerForRemoteNotifications

    Set this to true to initiate the registration process with Apple Push Notification service after the user has granted authorization If registration succeeds the DeviceToken will be returned. You should pass this token along to the server you use to generate remote notifications for the device.

    Properties

    DeviceToken

    A globally unique token that identifies this device to Apple Push Notification Network. Send this token to the server that you use to generate remote notifications. Your server must pass this token unmodified back to APNs when sending those remote notifications. This property will be empty if you set the registerForRemoteNotifications parameter to false when creating the Authorization request or if the app fails registration with the APN.

    Declaration
    public string DeviceToken { get; }
    Property Value
    Type Description
    String

    Error

    Contains error information of the request failed for some reason or an empty string if no error occurred.

    Declaration
    public string Error { get; }
    Property Value
    Type Description
    String

    Granted

    A property indicating whether authorization was granted. The value of this parameter is set to true when authorization was granted for one or more options. The value is set to false when authorization is denied for all options.

    Declaration
    public bool Granted { get; }
    Property Value
    Type Description
    Boolean

    IsFinished

    Indicates whether the authorization request has completed.

    Declaration
    public bool IsFinished { get; }
    Property Value
    Type Description
    Boolean

    Methods

    Dispose()

    Declaration
    public void Dispose()
    In This Article
    • Constructors
      • AuthorizationRequest(AuthorizationOption, Boolean)
    • Properties
      • DeviceToken
      • Error
      • Granted
      • IsFinished
    • Methods
      • Dispose()
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023