Example #1
0
    void Start()
    {
        extraMessage = null;

        // Enable line below to debug issues with setuping OneSignal. (logLevel, visualLogLevel)
        OneSignal.SetLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);

        // If you set to true, the user will have to provide consent
        // using OneSignal.UserDidProvideConsent(true) before the
        // SDK will initialize
        OneSignal.SetRequiresUserPrivacyConsent(requiresUserPrivacyConsent);

        // The only required method you need to call to setup OneSignal to receive push notifications.
        // Call before using any other methods on OneSignal (except setLogLevel or SetRequiredUserPrivacyConsent)
        // Should only be called once when your app is loaded.
        // OneSignal.Init(OneSignal_AppId);
        OneSignal.StartInit("241adf49-a128-4b4b-830a-5edd482602b3")
        .HandleNotificationReceived(HandleNotificationReceived)
        .HandleNotificationOpened(HandleNotificationOpened)
        .HandleInAppMessageClicked(HandlerInAppMessageClicked)
        .EndInit();

        OneSignal.inFocusDisplayType         = OneSignal.OSInFocusDisplayOption.Notification;
        OneSignal.permissionObserver        += OneSignal_permissionObserver;
        OneSignal.subscriptionObserver      += OneSignal_subscriptionObserver;
        OneSignal.emailSubscriptionObserver += OneSignal_emailSubscriptionObserver;

        var pushState = OneSignal.GetPermissionSubscriptionState();

        OneSignalInAppMessageTriggerExamples();
    }
Example #2
0
    public void SetFirebaseProfile()
    {
        Dictionary <string, object> requests = new Dictionary <string, object>()
        {
        };
        Dictionary <string, object> coinsInfo = new Dictionary <string, object>()
        {
            { "LastRequest", "none" },
            { "ConsecutiveDays", "0" }
        };

        Dictionary <string, object> user = new Dictionary <string, object>
        {
            { "id", PlayerPrefs.GetString("myRoomID").ToLower() },
            { "requests", requests },
            { "coins", "0" },
            { "coinsInfo", coinsInfo }
        };
        DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;

        reference.Child("users").Child(username.ToLower()).SetValueAsync(user);
        OSPermissionSubscriptionState status = OneSignal.GetPermissionSubscriptionState();
        string oneSignalID = (status.subscriptionStatus.userId != null) ? status.subscriptionStatus.userId : "1";
        Dictionary <string, object> usernameList = new Dictionary <string, object> {
            { username.ToLower(), oneSignalID }
        };

        reference.Child("usernameList").UpdateChildrenAsync(usernameList);
    }
Example #3
0
    void Start()
    {
        extraMessage = null;

        // Enable line below to debug issues with setuping OneSignal. (logLevel, visualLogLevel)
        OneSignal.SetLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);

        // The only required method you need to call to setup OneSignal to receive push notifications.
        // Call before using any other methods on OneSignal.
        // Should only be called once when your app is loaded.
        // OneSignal.Init(OneSignal_AppId);
        OneSignal.StartInit("b2f7f966-d8cc-11e4-bed1-df8f05be55ba")
        .HandleNotificationReceived(HandleNotificationReceived)
        .HandleNotificationOpened(HandleNotificationOpened)
        //.InFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
        .EndInit();

        OneSignal.inFocusDisplayType    = OneSignal.OSInFocusDisplayOption.Notification;
        OneSignal.permissionObserver   += OneSignal_permissionObserver;
        OneSignal.subscriptionObserver += OneSignal_subscriptionObserver;

        var pushState = OneSignal.GetPermissionSubscriptionState();

        Debug.Log("pushState.subscriptionStatus.subscribed : " + pushState.subscriptionStatus.subscribed);
        Debug.Log("pushState.subscriptionStatus.userId : " + pushState.subscriptionStatus.userId);
    }
Example #4
0
        public void SetFirebaseProfile()
        {
            DatabaseReference             reference = FirebaseDatabase.DefaultInstance.RootReference;
            OSPermissionSubscriptionState status    = OneSignal.GetPermissionSubscriptionState();
            string oneSignalID = (status.subscriptionStatus.userId != null) ? status.subscriptionStatus.userId : "1";
            Dictionary <string, object> usernameList = new Dictionary <string, object> {
                { username.ToLower(), oneSignalID }
            };

            reference.Child("usernameList").UpdateChildrenAsync(usernameList);
        }
Example #5
0
 private void OneSignal_permissionObserver(OSPermissionStateChanges stateChanges)
 {
     if (stateChanges.from.status == OSNotificationPermission.NotDetermined)
     {
         if (stateChanges.to.status == OSNotificationPermission.Authorized)
         {
             Debug.Log("Thanks for accepting notifications!");
             OneSignal.SetSubscription(true);
             PostNotification(OneSignal.GetPermissionSubscriptionState().subscriptionStatus.userId);
         }
         else if (stateChanges.to.status == OSNotificationPermission.Denied)
         {
             Debug.Log("Notifications not accepted. You can turn them on later under your device settings.");
         }
     }
 }
    // Test Notification

    private void SendNotification()
    {
        var extraMessage = "";

        OneSignal.IdsAvailable((userId, pushToken) => {
            userId = OneSignal.GetPermissionSubscriptionState().subscriptionStatus.userId;

            if (pushToken != null)
            {
                // See http://documentation.onesignal.com/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", "Made with Unity" }
                };
                // Send notification to this device.
                notification["include_player_ids"] = new List <string>()
                {
                    userId
                };
                // Example of scheduling a notification in the future.
                notification["send_after"] = DateTime.Now.ToUniversalTime().AddSeconds(0).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.";
            }
        });
    }
Example #7
0
    private void GenerateLink(CloData cloData, TrackLinkData trackLinkData, Action linkGeneratedCallback)
    {
        RequestAdvertiserId(advertiserId =>
        {
            RequestAppMetricaDeviceId((metricaId) =>
            {
                var queryMap = new Dictionary <string, string>();

                queryMap["key"] = trackLinkData.key;

                if (!string.IsNullOrEmpty(trackLinkData.sub1))
                {
                    queryMap["sub1"] = trackLinkData.sub1;
                }
                if (!string.IsNullOrEmpty(trackLinkData.sub2))
                {
                    queryMap["sub2"] = trackLinkData.sub2;
                }
                if (!string.IsNullOrEmpty(trackLinkData.sub3))
                {
                    queryMap["sub3"] = trackLinkData.sub3;
                }

                var appsflyerId = AppsFlyer.getAppsFlyerId();
                if (string.IsNullOrEmpty(appsflyerId))
                {
                    appsflyerId = "none";
                }

                if (cloData.integration_version == "v1")
                {
                    var sub5 = $"{trackLinkData.source}:{advertiserId}:{appsflyerId}:{metricaId}";

                    queryMap["sub4"] = _appIdentifier;
                    queryMap["sub5"] = sub5;
                }
                else
                {
                    queryMap["bundle"]     = _appIdentifier;
                    queryMap["metrica_id"] = metricaId;
                    queryMap["apps_id"]    = appsflyerId;
                    queryMap["ifa"]        = advertiserId;

                    try
                    {
                        var subscriptionOneSignalStatus = OneSignal.GetPermissionSubscriptionState();
                        queryMap["onesignal_id"]        =
                            string.IsNullOrEmpty(subscriptionOneSignalStatus.subscriptionStatus.userId)
                                ? "none"
                                : subscriptionOneSignalStatus.subscriptionStatus.userId;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e + "EXCEPTION!!!!!!!!!!!!!!");
                    }

                    queryMap["source"] = trackLinkData.source;
                }

                var trackLink = $"https://{cloData.track_domain}/click.php";
                var index     = 0;
                foreach (var pair in queryMap)
                {
                    trackLink += index == 0 ? "?" : "&";

                    trackLink += $"{pair.Key}={queryMap[pair.Key]}";
                    index++;
                }

                UnityMainThreadDispatcher.Instance().Enqueue(SaveTrackLink(trackLink, linkGeneratedCallback));
            });
        });
    }
Example #8
0
 public void PostNotification()
 {
     GameObject.Find("Notification Manager").GetComponent <NotificationManager>().PostNotification(OneSignal.GetPermissionSubscriptionState().subscriptionStatus.userId);
 }