At least, it helped someone…

Yesterday, I was comparing french cloud game hosting service Clan of the Cloud with one of its most important competitors GameSparks for some side projects. What a surprise when I found portions of my code from this post was used in the official documentation of GameSparks without a single credit to me or to Cheese Burgames.

Despite the fact the related bug was fixed in Unity long ago before the release of the article, the author does not warn users that our workaround is not the official supported way to trigger notification support on Unity.

Even if my blog is not a popular place on the internet, it seems my solution has been useful to someone (and it confirms is a very good platform for search engine discovery). It just would have been really cooler to add a mention.

Unity Pro Tip #2: iOS 8 Push Notifications

UPDATE: This bug has been fixed in Unity 4.5.5p1 (released October 16th, 2014) and in Unity 4.6.0p1 (released december 4th, 2014).

Now iOS 8 is out, we have to release updates for our Unity apps. Here at Cheese Burgames, we are preparing the first update for our first game, Echoes: Deep-sea Exploration. But during our pre-release tests, I noticed that remote notifications were not working anymore. Why that?

The answer is in the deprecation of the UIApplication’s registerForRemoteNotificationTypes: method in iOS 8.

Internally, NotificationServices.RegisterForRemoteNotificationTypes calls it. And now, it does not produce any result. Instead, you will see this message in the Xcode debug console:

registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.

Nothing less, nothing more. And as of the currently available version of Unity (4.5.4f1) or in patch releases, there is no workaround. But we have a solution!

The Quick Fix

To resolve this issue, you have to use an iOS plugin and a script.

First, create a file called in your Assets/Plugins/iOS folder (create this folder if it does not exist yet). Here is the content of this file:

#import <UIKit/UIKit.h>

extern "C" {
    void CBG_RegisterForRemoteNotifications(int types) {
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:Nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];

After that, create a C# script called CBGNotificationServices.cs in your Assets folder (or anywhere else you store your player scripts) and fill it with these lines:

using UnityEngine;
using System.Runtime.InteropServices;

public class CBGNotificationServices {

    [DllImport ("__Internal")]
    private static extern void CBG_RegisterForRemoteNotifications(int types);
    public static void RegisterForRemoteNotificationsTypes(RemoteNotificationType types) {
        if (!Application.isEditor) {
            string sysInfo = SystemInfo.operatingSystem;
            sysInfo = sysInfo.Replace("iPhone OS ", "");
            string[] chunks = sysInfo.Split('.');
            int majorVersion = int.Parse(chunks[0]);
            if (majorVersion >= 8)
                CBG_RegisterForRemoteNotifications((int) types);

Now, anywhere you are using NotificationServices.RegisterForRemoteNotificationsTypes(), you can simply replace it by:

CBGNotificationServices.RegisterForRemoteNotificationsTypes(/* Your remote notification types here */);

And you’re done!

This solution is a temporary one. It is working in our app but we recommend very careful testing before using it in a release. The bug has been reported and I hope the Unity team will soon provide a permanent fix.