Пример #1
0
    public void Init()
    {
        if (!OneSignalInit)
        {
            switch (Application.bundleIdentifier)
            {
            case "com.monsmile.projecth.ios.dev":
            case "com.monsmile.herocry.ios.dev":
                OneSignal.Init("b4c915a0-4494-4d6e-8ade-efce0a40ad01", string.Empty, HandleNotification);
                break;

            case "com.monsmile.projecth.ios":
                OneSignal.Init("517412e4-b97d-4b24-9681-9f4dfc26fa00", string.Empty, HandleNotification);
                break;

            case "com.monsmile.projecth.android.dev":
                OneSignal.Init("b4c915a0-4494-4d6e-8ade-efce0a40ad01", "357018248098", HandleNotification, true);
                OneSignal.EnableNotificationsWhenActive(false);
                break;

            case "com.monsmile.projecth.android.test":
                OneSignal.Init("517412e4-b97d-4b24-9681-9f4dfc26fa00", "725610003103", HandleNotification);
                OneSignal.EnableNotificationsWhenActive(false);
                break;
            }
            OneSignalInit = true;
        }
        ResetBadgeNumber();

        OneSignal.SetSubscription(true);
        OneSignal.GetIdsAvailable(SetPushInfo);
    }
Пример #2
0
 public void getids()
 {
     OneSignal.GetIdsAvailable((userId, pushToken) => {
         CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
             idsavailableevent(this, new GetIdsEventArgs()
             {
                 userId = userId, pushToken = pushToken
             });
         });
     });
 }
    // Test Menu
    // Includes SendTag/SendTags and getting the userID and pushToken
    void OnGUI()
    {
        GUIStyle customTextSize = new GUIStyle("button");

        customTextSize.fontSize = 30;

        GUIStyle guiBoxStyle = new GUIStyle("box");

        guiBoxStyle.fontSize = 30;

        GUI.Box(new Rect(10, 10, 390, 250), "Test Menu", guiBoxStyle);

        if (GUI.Button(new Rect(60, 80, 300, 60), "SendTags", customTextSize))
        {
            // You can tags users with key value pairs like this:
            OneSignal.SendTag("UnityTestKey", "TestValue");
            // Or use an IDictionary if you need to set more than one tag.
            OneSignal.SendTags(new Dictionary <string, string>()
            {
                { "UnityTestKey2", "value2" }, { "UnityTestKey3", "value3" }
            });

            // You can delete a single tag with it's key.
            // OneSignal.DeleteTag("UnityTestKey");
            // Or delete many with an IList.
            // OneSignal.DeleteTags(new List<string>() {"UnityTestKey2", "UnityTestKey3" });
        }

        if (GUI.Button(new Rect(60, 170, 300, 60), "GetIds", customTextSize))
        {
            OneSignal.GetIdsAvailable((userId, pushToken) => {
                extraMessage = "UserID:\n" + userId + "\n\nPushToken:\n" + pushToken;
            });
        }

        if (extraMessage != null)
        {
            guiBoxStyle.alignment = TextAnchor.UpperLeft;
            guiBoxStyle.wordWrap  = true;
            GUI.Box(new Rect(10, 300, Screen.width - 20, Screen.height - 310), extraMessage, guiBoxStyle);
        }
    }
    public void sendPushMessage(string message, string title = "Kubera")
    {
        OneSignal.GetIdsAvailable((userId, pushToken) => {
            if (pushToken != null)
            {
                // See http://documentation.onesignal.com/v2.0/docs/notifications-create-notification for a full list of options.
                // You can not use included_segments or any fields that require your OneSignal 'REST API Key' in your app for security reasons.
                // If you need to use your OneSignal 'REST API Key' you will need your own server where you can make this call.

                var notification         = new Dictionary <string, object>();
                notification["contents"] = new Dictionary <string, string>()
                {
                    { "en", "Test Message" }
                };
                notification["headings"] = new Dictionary <string, string>()
                {
                    { "en", title }
                };
                // Send notification to this device.
                notification["include_player_ids"] = new List <string>()
                {
                    userId
                };
                // Example of scheduling a notification in the future.
                notification["send_after"] = System.DateTime.Now.ToUniversalTime().AddSeconds(30).ToString("U");

                //extraMessage = "Posting test notification now.";
                OneSignal.PostNotification(notification, (responseSuccess) => {
                    //extraMessage = "Notification posted successful! Delayed by about 30 secounds to give you time to press the home button to see a notification vs an in-app alert.\n" + Json.Serialize(responseSuccess);
                }, (responseFailure) => {
                    //extraMessage = "Notification failed to post:\n" + Json.Serialize(responseFailure);
                });
            }
            else
            {
                Debug.LogWarning("ERROR: Device is not registered.");
            }
        });
    }
Пример #5
0
    // Test Menu
    // Includes SendTag/SendTags, getting the userID and pushToken, and scheduling an example notification
    void OnGUI()
    {
        GUIStyle customTextSize = new GUIStyle("button");

        customTextSize.fontSize = 30;

        GUIStyle guiBoxStyle = new GUIStyle("box");

        guiBoxStyle.fontSize = 30;

        GUI.Box(new Rect(10, 10, 390, 340), "Test Menu", guiBoxStyle);

        if (GUI.Button(new Rect(60, 80, 300, 60), "SendTags", customTextSize))
        {
            // You can tags users with key value pairs like this:
            OneSignal.SendTag("UnityTestKey", "TestValue");
            // Or use an IDictionary if you need to set more than one tag.
            OneSignal.SendTags(new Dictionary <string, string>()
            {
                { "UnityTestKey2", "value2" }, { "UnityTestKey3", "value3" }
            });

            // You can delete a single tag with it's key.
            // OneSignal.DeleteTag("UnityTestKey");
            // Or delete many with an IList.
            // OneSignal.DeleteTags(new List<string>() {"UnityTestKey2", "UnityTestKey3" });
        }

        if (GUI.Button(new Rect(60, 170, 300, 60), "GetIds", customTextSize))
        {
            OneSignal.GetIdsAvailable((userId, pushToken) => {
                extraMessage = "UserID:\n" + userId + "\n\nPushToken:\n" + pushToken;
            });
        }

        if (GUI.Button(new Rect(60, 260, 300, 60), "TestNotification", customTextSize))
        {
            extraMessage = "Waiting to get a OneSignal userId. Uncomment OneSignal.SetLogLevel in the Start method if it hangs here to debug the issue.";
            OneSignal.GetIdsAvailable((userId, pushToken) => {
                if (pushToken != null)
                {
                    // See http://documentation.onesignal.com/v2.0/docs/notifications-create-notification for a full list of options.
                    // You can not use included_segments or any fields that require your OneSignal 'REST API Key' in your app for security reasons.
                    // If you need to use your OneSignal 'REST API Key' you will need your own server where you can make this call.

                    var notification         = new Dictionary <string, object>();
                    notification["contents"] = new Dictionary <string, string>()
                    {
                        { "en", "Test Message" }
                    };
                    // Send notification to this device.
                    notification["include_player_ids"] = new List <string>()
                    {
                        userId
                    };
                    // Example of scheduling a notification in the future.
                    notification["send_after"] = System.DateTime.Now.ToUniversalTime().AddSeconds(30).ToString("U");

                    extraMessage = "Posting test notification now.";
                    OneSignal.PostNotification(notification, (responseSuccess) => {
                        extraMessage = "Notification posted successful! Delayed by about 30 secounds to give you time to press the home button to see a notification vs an in-app alert.\n" + Json.Serialize(responseSuccess);
                    }, (responseFailure) => {
                        extraMessage = "Notification failed to post:\n" + Json.Serialize(responseFailure);
                    });
                }
                else
                {
                    extraMessage = "ERROR: Device is not registered.";
                }
            });
        }

        if (extraMessage != null)
        {
            guiBoxStyle.alignment = TextAnchor.UpperLeft;
            guiBoxStyle.wordWrap  = true;
            GUI.Box(new Rect(10, 390, Screen.width - 20, Screen.height - 400), extraMessage, guiBoxStyle);
        }
    }
 public void GameThriveGetIdsAvailable_managed()
 {
     OneSignal.GetIdsAvailable((playerID, channelUri) => {
         m_Native.CLR_TO_MARM_IdsAvailableCallback_GameThrive(playerID, (channelUri == null) ? "" : channelUri);
     });
 }
 public void OneSignalGetIdsAvailable_managed()
 {
     OneSignal.GetIdsAvailable((userID, channelUri) => {
         m_Native.CLR_TO_MARM_IdsAvailableCallback(userID, (channelUri == null) ? "" : channelUri);
     });
 }