Exemplo n.º 1
0
        public static InAppMessage FromAndroid(AndroidJavaObject androidObject)
        {
            var inapp = new InAppMessage();

            try {
                var inappJson = PusheAndroidUtils.Extension("inappmessaging").CallStatic <string>("inAppToJson", androidObject);
                inapp = JsonUtility.FromJson <InAppMessage>(inappJson);
            } catch (Exception e) {
                PusheUnity.Log("Failed to parse inapp message.\n" + e);
            }
            return(inapp);
        }
Exemplo n.º 2
0
        public static NotificationButtonData FromAndroid(AndroidJavaObject androidJavaObject)
        {
            NotificationButtonData button = new NotificationButtonData();

            try {
                string json = PusheAndroidUtils.Extension("notification").CallStatic <string>("notificationButtonToJson", androidJavaObject);
                button = JsonUtility.FromJson <NotificationButtonData>(json);
            } catch (Exception e) {
                PusheUnity.Log("Failed to parse notification " + e);
            }
            return(button);
        }
Exemplo n.º 3
0
    private void InitializeSomeMethods()
    {
        // Listen to Register
        PusheUnity.OnPusheRegistered(OnPusheRegisteredSuccessfully);
        PusheUnity.OnPusheInitialized(() =>
        {
            PusheUnity.Log("Pushe Modules have initialized successfully.");
        });
        // Set notification listener
        PusheNotification.SetNotificationListener(new PusheNotifListener());

        // Check if pushe is already registered
        PusheUnity.Log(PusheUnity.IsRegistered() ? "Pushe is registered" : "Pushe is NOT registered!");
    }
Exemplo n.º 4
0
    /**
     * Called when Pushe is registered.
     */
    private void OnPusheRegisteredSuccessfully()
    {
        PusheUnity.Log(" --- Pushe has been REGISTERED to server successfully --- ");
        var adId = PusheUnity.GetAdvertisingId();

        PusheUnity.Log("Ad id: " + adId);
        var deviceId = PusheUnity.GetDeviceId();

        PusheUnity.Log("Device id : " + deviceId);

        // Pushe Notification

        PusheUnity.Log("Notification enabled? " + PusheNotification.IsNotificationEnabled());
        PusheUnity.Log("Custom sound enabled? " + PusheNotification.IsCustomSoundEnabled());
        PusheNotification.CreateNotificationChannel("CustomChannel", "CustomChannel");

        // Analytics
        PusheAnalytics.SendEvent("Some_Event");
        PusheAnalytics.SendEcommerceData("EcommerceData", 12.0);

        PusheUnity.Log("Subscribing to test1");
        PusheUnity.Subscribe("test1");

        PusheUnity.Log("Set 123123 as custom id");
        PusheUnity.SetCustomId("123123");
        PusheUnity.Log("CustomId is: " + PusheUnity.GetCustomId());

        var tags = new Dictionary <string, string> {
            { "name", "Mohammad" }, { "age", "25" }, { "birthday", "1435187386" }
        };

        PusheUnity.AddTags(tags);

        PusheUnity.RemoveTags("name", "age");

        PusheUnity.Log("Tags: " + PusheUnity.GetSubscribedTags());
        PusheUnity.Log("Topics: " + string.Join(",", PusheUnity.GetSubscribedTopics()));

        PusheInAppMessaging.DisableInAppMessaging();
        PusheUnity.Log("Is in app messaging enabled?" + PusheInAppMessaging.IsInAppMessagingEnabled());
        PusheInAppMessaging.EnableInAppMessaging();
        PusheUnity.Log("Is in app messaging enabled? " + PusheInAppMessaging.IsInAppMessagingEnabled());
        PusheInAppMessaging.TriggerEvent("qqq");
        PusheInAppMessaging.SetInAppMessagingListener(new InAppMessagingListener());
    }
Exemplo n.º 5
0
 public void OnNotification(NotificationData notificationData)
 {
     PusheUnity.Log("Notification received: " + notificationData);
 }
Exemplo n.º 6
0
 public void OnInAppMessageButtonClicked(InAppMessage inAppMessage, int index)
 {
     PusheUnity.Log("In app message button: " + inAppMessage.title + " index: " + index);
 }
Exemplo n.º 7
0
 public void OnInAppMessageDismissed(InAppMessage inAppMessage)
 {
     PusheUnity.Log("In app message dismissed: " + inAppMessage.title);
 }
Exemplo n.º 8
0
 /// Trigger a local event. Local event is useless for sending data to server.
 /// Since no data is sent to server. Local events are only useful for triggering an in app messaging
 /// which is stored before. If you want to send data to server
 public static void TriggerEvent(string eventName)
 {
     PusheUnity.Log("Triggering local event " + eventName);
     PiamService().Call("triggerEvent", eventName);
 }
Exemplo n.º 9
0
 // Use this for initialization
 private void Start()
 {
     PusheUnity.Log("Starting Pushe sample script");
     InitializeSomeMethods();
 }
Exemplo n.º 10
0
 public void OnButtonClick(NotificationButtonData notificationButtonData, NotificationData notificationData)
 {
     PusheUnity.Log("Notification button clicked\n Data: " + notificationData +
                    "\n ButtonData: " + notificationButtonData);
 }
Exemplo n.º 11
0
 public void OnNotificationDismiss(NotificationData notificationData)
 {
     PusheUnity.Log("Notification dismissed: " + notificationData);
 }
Exemplo n.º 12
0
 /// **VisibleForTesting**
 /// In order to test a message locally using code
 /// you can use this function to test the message that is used in API\
 /// Note that the function should ONLY BE USED FOR TESTING and does not send any info
 /// and will not trigger any callback
 /// <param name="message">Is a json string adopted from Restful-API body</param>
 /// <param name="instant">Tells if messsage should be triggered instantly or wait for it's display conditions.</param>
 public static void TestInAppMessage(string message, bool instant = false)
 {
     PusheUnity.Log("Sending test message to InAppMessaging module\nMessage:" + message);
     PiamService().Call("testInAppMessage", new object[] { message, instant });
 }
Exemplo n.º 13
0
 public static void DisableInAppMessaging()
 {
     PusheUnity.Log("Disabling InAppMessaging");
     PiamService().Call("disableInAppMessaging");
 }
Exemplo n.º 14
0
 public void OnCustomContentReceived(string customJson)
 {
     PusheUnity.Log("Notification custom content received: " + customJson);
 }
Exemplo n.º 15
0
 public void OnInAppMessageTriggered(InAppMessage inAppMessage)
 {
     PusheUnity.Log("In app message triggered: " + inAppMessage.title);
 }
Exemplo n.º 16
0
 public void OnNotificationClick(NotificationData notificationData)
 {
     PusheUnity.Log("Notification clicked: " + notificationData);
 }
Exemplo n.º 17
0
 public void OnInAppMessageClicked(InAppMessage inAppMessage)
 {
     PusheUnity.Log("In app message Clicked: " + inAppMessage.title);
 }
Exemplo n.º 18
0
        /// <summary>
        /// With this function you can send notification from user to user.
        /// </summary>
        /// <exception cref="Exception">Will be thrown if needed param was entered as a null value</exception>
        public static void SendNotificationToUser(UserNotification userNotification)
        {
            if (userNotification.Id == null || userNotification.Title == null || userNotification.Content == null)
            {
                throw new Exception("id, title and content must be set.");
            }

            var userNotifClass = new AndroidJavaClass("co.pushe.plus.notification.UserNotification");
            AndroidJavaObject userNotif;

            switch (userNotification.Type)
            {
            case UserNotification.IdType.CustomId:
                userNotif = userNotifClass.CallStatic <AndroidJavaObject>("withCustomId", userNotification.Id);
                break;

            case UserNotification.IdType.AndroidId:
                userNotif = userNotifClass.CallStatic <AndroidJavaObject>("WithAndroidId", userNotification.Id);
                break;

            case UserNotification.IdType.GoogleAdId:
                userNotif = userNotifClass.CallStatic <AndroidJavaObject>("withAdvertisementId",
                                                                          userNotification.Id);
                break;

            default:
                throw new Exception("IdType is not valid");
            }

            userNotif = userNotif.Call <AndroidJavaObject>("setTitle", userNotification.Title)
                        .Call <AndroidJavaObject>("setContent", userNotification.Content);
            if (userNotification.IconUrl != null)
            {
                userNotif = userNotif.Call <AndroidJavaObject>("setIconUrl", userNotification.IconUrl);
            }

            if (userNotification.BigTitle != null)
            {
                userNotif = userNotif.Call <AndroidJavaObject>("setBigTitle", userNotification.BigTitle);
            }

            if (userNotification.BigContent != null)
            {
                userNotif = userNotif.Call <AndroidJavaObject>("setBigContent", userNotification.BigContent);
            }

            if (userNotification.ImageUrl != null)
            {
                userNotif = userNotif.Call <AndroidJavaObject>("setImageUrl", userNotification.ImageUrl);
            }

            if (userNotification.CustomContent != null)
            {
                userNotif = userNotif.Call <AndroidJavaObject>("setCustomContent", userNotification.CustomContent);
            }

            if (userNotification.AdvancedJson != null)
            {
                userNotif = userNotif.Call <AndroidJavaObject>("setAdvancedNotification", userNotification.AdvancedJson);
            }

            if (userNotification.NotifIcon != null)
            {
                userNotif = userNotif.Call <AndroidJavaObject>("setNotifIcon", userNotification.NotifIcon);
            }

            try
            {
                PusheAndroidUtils.PusheNotificationService().Call("sendNotificationToUser", userNotif);
            }
            catch (Exception e)
            {
                PusheUnity.Log("Could not send a notification " + e);
            }
        }
Exemplo n.º 19
0
    /**
     * Called when Pushe is registered.
     */
    private void OnPusheRegisteredSuccessfully()
    {
        PusheUnity.Log(" --- Pushe has been REGISTERED to server successfully --- ");
        var adId = PusheUnity.GetAdvertisingId();

        PusheUnity.Log("Ad id: " + adId);
        var deviceId = PusheUnity.GetDeviceId();

        PusheUnity.Log("Device id : " + deviceId);

        // Pushe Notification

        PusheUnity.Log("Notification enabled? " + PusheNotification.IsNotificationEnabled());
        PusheUnity.Log("Custom sound enabled? " + PusheNotification.IsCustomSoundEnabled());
        // PusheNotification.CreateNotificationChannel("CustomChannel", "CustomChannel");
        PusheUnity.Log("Sending d2d");
        PusheNotification.SendNotificationToUser(UserNotification.WithDeviceId(PusheUnity.GetDeviceId()).SetTitle("Title").SetContent("Content"));
        // Analytics
        PusheAnalytics.SendEvent("Some_Event");
        PusheAnalytics.SendEcommerceData("EcommerceData", 12.0);

        PusheUnity.Log("Subscribing to test1");
        PusheUnity.Subscribe("test1");

        PusheUnity.Log("Set 123123 as custom id");
        PusheUnity.SetCustomId("123123");
        PusheUnity.Log("CustomId is: " + PusheUnity.GetCustomId());

        var tags = new Dictionary <string, string> {
            { "name", "Mohammad" }, { "age", "25" }, { "birthday", "1435187386" }
        };

        PusheUnity.AddTags(tags);

        PusheUnity.RemoveTags("name", "age");

        PusheUnity.Log("Tags: " + PusheUnity.GetSubscribedTags());
        PusheUnity.Log("Topics: " + string.Join(",", PusheUnity.GetSubscribedTopics()));

        // InAppMessaging
        PusheInAppMessaging.DisableInAppMessaging();
        PusheUnity.Log("Is in app messaging enabled?" + PusheInAppMessaging.IsInAppMessagingEnabled());
        PusheInAppMessaging.EnableInAppMessaging();
        PusheUnity.Log("Is in app messaging enabled? " + PusheInAppMessaging.IsInAppMessagingEnabled());
        PusheInAppMessaging.TriggerEvent("qqq");
        PusheInAppMessaging.SetInAppMessagingListener(new InAppMessagingListener());

        // FCM token and ...
        var fcmToken      = PusheUnity.GetFcmToken();
        var hmsToken      = PusheUnity.GetHmsToken();
        var activeService = PusheUnity.GetActiveService();

        PusheUnity.Log("Fcm token: " + fcmToken + "\nHms token: " + hmsToken + "\nActive service: " + activeService);

        // Foreground awareness feature of notification
        PusheUnity.Log("Are all notifications aware of foreground state? " + PusheUnity.IsForceForegroundAware());
        PusheUnity.Log("Toggle to true");
        PusheUnity.EnableNotificationForceForegroundAware();
        PusheUnity.Log("Are all notifications aware of foreground state? " + PusheUnity.IsForceForegroundAware());
        PusheUnity.Log("Toggle back to false");
        PusheUnity.DisableNotificationForceForegroundAware();
        PusheUnity.Log("Are all notifications aware of foreground state? " + PusheUnity.IsForceForegroundAware());
    }