Unity Remote notification authorization request not showing up

883 Views Asked by At

I have a basic unity scene that involves a button which is linked to an OnClick method. I know this part works because I have the debug.log that tells me.

I tried looking all over the internet and stack overflow and couldn't find an answer to my problem.

The part that I suspect is the problem is the authorization request. I'm using Unity simulator for testing as well as the remote 5 app. When I play my project there is no request on either testing form for notifications. So my main question is why does the authorization request fail. I am using the mobile notifications package offered by Unity and have tried messing around with the settings there such as request authorization on app launch.

Part of what confuses me is that I got most of the code straight from Unity documentation.

using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Notifications.iOS;
using UnityEngine;

public class NotificationManager : MonoBehaviour
{
    private void Start()
    {
        StartCoroutine(RequestAuthorization());
    }
    IEnumerator RequestAuthorization()
    {
        using (var req = new AuthorizationRequest(AuthorizationOption.Alert | AuthorizationOption.Badge, true))
        {
            Debug.Log(req.IsFinished);
            while (!req.IsFinished)
            {
                yield return null;
            };

            string res = "\n RequestAuthorization:";
            res += "\n finished: " + req.IsFinished;
            res += "\n granted :  " + req.Granted;
            res += "\n error:  " + req.Error;
            res += "\n deviceToken:  " + req.DeviceToken;
            Debug.Log(res);
        }
    }
    
    public void OnClick()
    {
        Debug.Log("Sending Notif");
        SendNotification();
    }
    
    private void SendNotification()
    {
        var timeTrigger = new iOSNotificationTimeIntervalTrigger()
        {
            TimeInterval = new TimeSpan(0, 0, 1),
            Repeats = false
        };

        var notification = new iOSNotification()
        {
            // You can specify a custom identifier which can be used to manage the notification later.
            // If you don't provide one, a unique string will be generated automatically.
            Identifier = "testNotification",
            Title = "Test Notification",
            Body = "Testing the notification capability",
            Subtitle = "What does the subtitle look like",
            ShowInForeground = true,
            ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
            CategoryIdentifier = "category_a",
            ThreadIdentifier = "thread1",
            Trigger = timeTrigger,
        };

        iOSNotificationCenter.ScheduleNotification(notification);
    }
}
0

There are 0 best solutions below