Push Notifications For Unity iOS

If you wish to use any of the Push Campaign or Push Point features of User Hook, you will need to follow a few additional steps while setting up your app.

First, you will need to create the appropriate push certificates through the Apple Member Center. Once you have created your certificate, you will need to upload this certificate through the User Hook admin website.

Sandbox vs Production

While developing your app locally, push messages will be sent through Apple’s Sandbox environment. In order to receive these sandbox push notifications, you will need to upload a certificate for the “Sandbox Certificate”. Once your app is live in iTunes, all push messages will be sent using Apple’s Production servers and will use the corresponding “Production Certificate”. User Hook automatically determines if the app is running as a local development build or as a published live build. You do not need to make any changes inside your app to handle the sandbox/production differences.

Initialize User Hook for Push Notifications

For iOS apps, you will need to explicitly tell User Hook that you want to register to push notifications. All you need to do is use the following code.

// setup push notifications
UserHook.Instance.registerForPushNotifications();

Handling Push Notification Payloads

When your iOS app receives a push notification, it will have access to the Payload data that was defined in the User Hook admin site. If your app will be using this payload data, you will need to setup a payload handler.

Changes to Xcode Settings

You will need to make a few changes to your Xcode project for push notifications. After making these changes, make sure that subsequent exports are done using the “append” option, not the “replace” option. Otherwise you will have to make these changes after every export.

Under the “Capabilities” settings, you will need to enable “Push Notifications”.

While developing your app on a local device, push notifications will be sent through Apple’s Sandbox servers. To enable User Hook to automatically detect that your device is using a development version of the app, you need to add the following preprocessor Macro. Under the “Build Settings”, find the “Preprocessor Macros” setting and set the value to “DEBUG=1”.