Parse.com - iOS推送通知和Unity集成

时间:2014-08-11 07:17:46

标签: unity3d push-notification parse-platform apple-push-notifications

我注意到Parse Unity支持仍然没有为iOS提供推送通知。

有没有人通过Parse实现Unity插件或其他解决方案来支持iOS推送通知?

(Cross Unity Answers发布。)

2 个答案:

答案 0 :(得分:3)

现在实际上可以使用ParseObject来模拟ParseInstallation对象。

请点击此处:https://gist.github.com/gfosco/a3d092651c32ba3385e6

解析Google群组中的说明:https://groups.google.com/d/msg/parse-developers/ku8-r91_o6s/6ioQ9T2TP7wJ

将此脚本附加到GameObject,用您自己的替换重要部分:

using UnityEngine;
using System.Collections;
using Parse;

public class PushBehaviorScript : MonoBehaviour {

    bool tokenSent = false;
    public ParseObject currentInstallation = null;

    void Start () {
        if (PlayerPrefs.HasKey ("currentInstallation")) {
            string objId = PlayerPrefs.GetString ("currentInstallation");
            currentInstallation = ParseObject.CreateWithoutData ("_Installation", objId);
        }

        if (currentInstallation == null) {
            #if UNITY_IPHONE && !UNITY_EDITOR
                NotificationServices.RegisterForRemoteNotificationTypes (RemoteNotificationType.Alert | RemoteNotificationType.Badge | RemoteNotificationType.Sound);
            #endif
        }
    }

    void  FixedUpdate () {
        if (!tokenSent && currentInstallation == null) {
            #if UNITY_IPHONE && !UNITY_EDITOR
                byte[] token   = NotificationServices.deviceToken;
                if(token != null) {
                    tokenSent = true;
                    string tokenString =  System.BitConverter.ToString(token).Replace("-", "").ToLower();
                    Debug.Log ("OnTokenReived");
                    Debug.Log (tokenString);
                    ParseObject obj = new ParseObject("_Installation");
                    obj["deviceToken"] = tokenString;
                    obj["appIdentifier"] = "com.parse.unitypush";
                    obj["deviceType"] = "ios";
                    obj["timeZone"] = "UTC";
                    obj["appName"] = "UnityPushTest";
                    obj["appVersion"] = "1.0.0";
                    obj["parseVersion"] = "1.3.0";
                    obj.SaveAsync().ContinueWith(t =>
                    {
                        if (obj.ObjectId != null) {
                            PlayerPrefs.SetString ("currentInstallation", obj.ObjectId);
                        }
                    });
                }
            #endif
        }
    }
}

答案 1 :(得分:0)

使用parse.com实现iOS推送您需要首先从apple获取令牌。然后保存当前安装 Unity现在已经构建了这个功能。

Highcharts.setOptions({
    global:{
        useUTC: false
    } 
});

在ParseManager(或用于管理解析>客户端通信的任何类)中

//push notification
bool tokenSent = false;


void RegisterForPush()
{
    Debug.Log("Register for push");
    tokenSent = false;

    #if UNITY_IOS
    UnityEngine.iOS.NotificationServices.RegisterForNotifications(NotificationType.Alert |
                                                            NotificationType.Badge |
                                                            NotificationType.Sound, true);

    #endif

}


void Update () {

        if (!tokenSent) {
            byte[] token = UnityEngine.iOS.NotificationServices.deviceToken;

            if (token != null) {
                // send token to a provider
                tokenSent = true;
                string hexToken = "%" + System.BitConverter.ToString(token).Replace('-', '%');

                #if UNITY_IOS
                    ParseManager.instance.RegisterForPush(hexToken);
                #endif

            }
        }
}

在Unity 5.1.2和iOS 8.4上测试