The question is answered, right answer was accepted
Cannot obtain apns token in Unity 5.4.0
After calling NotificationServices.RegisterForNotifications in new Unity 5.4.0f3 deviceToken is not received and registrationError also is null. In Unity 5.3.6 it works fine. Maybe anyone can provide a solution for this problem?
Answer by Omar_Unity · Sep 12, 2016 at 08:03 PM
That's a known bug which is being solved as you can see here: https://issuetracker.unity3d.com/issues/ios-push-notifications-not-enabled-in-xcode-project-when-notificationservices-are-used
There is a workaround that could help in the meantime:
You must insert the following line before calling "RegisterForNotifications":
var unused_var = typeof(UnityEngine.iOS.RemoteNotification);
For example your MonoBehaviour's start function could look like this:
void Start () {
var unused_var = typeof(UnityEngine.iOS.RemoteNotification);
tokenSent = false;
NotificationServices.RegisterForNotifications(NotificationType.Alert | NotificationType.Badge | NotificationType.Sound, true);
}
The statement will change the value of the preprocessor directive "UNITY_USES_REMOTE_NOTIFICATIONS" from default 0 to 1, at "Preprocessor.h" in the trampoline Xcode project.
Another way to do that is manually change the "#define UNITY_USES_REMOTE_NOTIFICATIONS" value to 1.
I hope that helps!
Answer by michaeltepl · Sep 12, 2016 at 08:23 PM
Thanks a lot for response! If to change this directive manually what is the exact place to do it (unity class or xcode project)?
On the Xcode project in the header file "Preprocessor.h".
Follow this Question
Related Questions
How to cancel iOS LocalNotification? 1 Answer
iOS notification with large icon using Unity Mobile Notifications Package 1 Answer
How to detect if push notification is launched from lock screen or received in-app 0 Answers
LocalNotification working not correct 0 Answers
Cross Platform Native Plugins - Android Notification 1 Answer