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

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

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

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

(交叉张贴在 Unity Answers 上。)

最佳答案

现在实际上是可能的,使用 ParseObject 来模拟 ParseInstallation 对象。

要点在这里:https://gist.github.com/gfosco/a3d092651c32ba3385e6

Parse Google Group 中的解释:https://groups.google.com/d/msg/parse-developers/ku8-r91_o6s/6ioQ9T2TP7wJ

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

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
        }
    }
}

关于unity3d - Parse.com - iOS 推送通知和 Unity 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25237736/

相关文章:

c# - 我应该使用什么来代替 OnMouseXXX 事件处理程序?

flutter - 如何构建 FCM 推送通知以在 Flutter 中的默认系统 Web 浏览器应用程序中打开指定的 URL(Android 和 iOS)

iOS - 通过本地推送通知触发通知服务扩展?

Android - 如果应用程序正在运行,停止(拦截)C2DM 推送通知?

ios - Swift Parse - 方法不会停止执行

javascript - parse.com JavaScript 应用程序。如何将其他用户角色更新为管理员

android - 在 Unity 上使用 Cardboard SDK 重新定位或重新定位 View

c# - 统一: Collider not resizing with Sprite Shape by Script

android - Unity ARFoundation Gradle构建失败-拒绝last-build.bin访问

ios - PFQueryTableViewController 错误