Sign In Register

How can we help you today?

Start a new topic
Answered

How do I get Push Notification for Unity3d Apps on iOS devices to work

I am working with Unity 4.5 and X-Code 6.1. The Instructions I found in the docs here, https://docs.gamesparks.net/howtos/push-notifications/how-to-configure-ios-push-notifications , don't seem to apply to the latest Unity3d build for X-Code.


Best Answer

I don't know which version of Unity you're using, but in our project we're using 4.6 b21 and I had to follow the instructions here to make it work:

https://chsxf.wordpress.com/2014/09/24/unity-pro-tip-2-ios-8-push-notifications/

Then in our main scene Start() function (or wherever you want the popup to show up) I coded this:

 

        private bool registrationErrorDone;
        private bool pushRegistrationRequestDone;
        
        
        voir Start()
        {
#if UNITY_IPHONE && !UNITY_EDITOR
            CBGNotificationServices.RegisterForRemoteNotificationTypes(RemoteNotificationType.Alert | RemoteNotificationType.Badge | RemoteNotificationType.Sound);
#endif
        }
        
        void Update()
        {
            ...
            ManagePushNotifications ()
            ...
        }
        
        private void ManagePushNotifications ()
        {
#if UNITY_IPHONE             
            if (!registrationErrorDone && NotificationServices.registrationError != null) {
                registrationErrorDone = true;
                Debug.Log ("NotificationServices.registrationError: " + NotificationServices.registrationError);
            }
            if (!pushRegistrationRequestDone && NotificationServices.deviceToken != null) {
                pushRegistrationRequestDone = true;
                string deviceToken = System.BitConverter.ToString (NotificationServices.deviceToken).Replace ("-", "").ToLower ();
                GameSparksSender sender = GameSparks.GameSparksApi.pushRegistrationRequest (deviceToken);
                sender.sendAsync ((response) => {});                
            }
#endif
        }

 



Hi Bolaji,


We can definitely look into this. Is there a paticular part where you can't progress or some sort of error message? Whatever details you can give would be great.


Shane

Sure Shane,


First of all the instructions ask you to edit AppDelegate.mm, but that does not exist in my project. Instead the functions that we are asked to modify exist in UnityAppController.mm.


After making the modifications in UnityAppController.mm  I get the error the GSApi is undefined. Since I don't know Objective C or Xcode very well. I do not know how to include that library or file and correct that error.

Looks like the SDK for GameSparks was not included when Unity built the project. So I have included it and other required libraries . I no longer receive compilation or linkage errors however my app still does not receive push notifications. In fact I don't even get the pop-up asking me if  I would like to allow it when I run the app.

Answer

I don't know which version of Unity you're using, but in our project we're using 4.6 b21 and I had to follow the instructions here to make it work:

https://chsxf.wordpress.com/2014/09/24/unity-pro-tip-2-ios-8-push-notifications/

Then in our main scene Start() function (or wherever you want the popup to show up) I coded this:

 

        private bool registrationErrorDone;
        private bool pushRegistrationRequestDone;
        
        
        voir Start()
        {
#if UNITY_IPHONE && !UNITY_EDITOR
            CBGNotificationServices.RegisterForRemoteNotificationTypes(RemoteNotificationType.Alert | RemoteNotificationType.Badge | RemoteNotificationType.Sound);
#endif
        }
        
        void Update()
        {
            ...
            ManagePushNotifications ()
            ...
        }
        
        private void ManagePushNotifications ()
        {
#if UNITY_IPHONE             
            if (!registrationErrorDone && NotificationServices.registrationError != null) {
                registrationErrorDone = true;
                Debug.Log ("NotificationServices.registrationError: " + NotificationServices.registrationError);
            }
            if (!pushRegistrationRequestDone && NotificationServices.deviceToken != null) {
                pushRegistrationRequestDone = true;
                string deviceToken = System.BitConverter.ToString (NotificationServices.deviceToken).Replace ("-", "").ToLower ();
                GameSparksSender sender = GameSparks.GameSparksApi.pushRegistrationRequest (deviceToken);
                sender.sendAsync ((response) => {});                
            }
#endif
        }

 


Login to post a comment