public void FireNotificationReceivedEvent(string jsonString, OneSignal.NotificationReceived notificationReceived)
    {
        var dict = Json.Deserialize(jsonString) as Dictionary <string, object>;
        Dictionary <string, object> additionalData = null;

        if (dict.ContainsKey("custom"))
        {
            additionalData = dict["custom"] as Dictionary <string, object>;
        }

        notificationReceived((string)(dict["alert"]), additionalData, (bool)dict["isActive"]);
    }
    public void FireNotificationReceivedEvent(string jsonString, OneSignal.NotificationReceived notificationReceived)
    {
        var dict = Json.Deserialize(jsonString) as Dictionary <string, object>;

        string message = (string)(dict["alertMessage"]);

        dict.Remove("alertMessage");

        bool isActive = (bool)dict["isActive"];

        dict.Remove("isActive");

        notificationReceived(message, dict, isActive);
    }
Exemple #3
0
        public static void Init(string appId, OneSignal.NotificationReceived inNotificationDelegate)
        {
            if (externalInitDone)
            {
                return;
            }

            var appCallbacksType = Type.GetType("UnityPlayer.AppCallbacks, UnityPlayer, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime");

            appCallbackInst       = appCallbacksType.GetRuntimeProperty("Instance").GetValue(null);
            getAppArgumentsMethod = appCallbacksType.GetRuntimeMethod("GetAppArguments", new Type[] {});

            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
                string args = (string)getAppArgumentsMethod.Invoke(appCallbackInst, new Object[] {});
                OneSignal.Init(appId, args, inNotificationDelegate, new ExternalInitUnity());
            });

            externalInitDone = true;
        }
Exemple #4
0
 // Doesn't apply to Windows Phone: The Callback is setup in the constructor so this is never called.
 public void FireNotificationReceivedEvent(string jsonString, OneSignal.NotificationReceived notificationReceived)
 {
 }
 public static void Init(string appId, OneSignal.NotificationReceived inNotificationDelegate)
 {
 }
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            OneSignal.NotificationReceived exampleNotificationReceivedDelegate = delegate(OSNotification notification)
            {
                try
                {
                    System.Console.WriteLine("OneSignal Notification Received: {0}", notification.payload.body);
                    Dictionary <string, object> additionalData = notification.payload.additionalData;

                    if (additionalData.Count > 0)
                    {
                        System.Console.WriteLine("additionalData: {0}", additionalData);
                    }
                }
                catch (System.Exception e)
                {
                    System.Console.WriteLine(e.StackTrace);
                }
            };

            // Notification Opened Delegate
            OneSignal.NotificationOpened exampleNotificationOpenedDelegate = delegate(OSNotificationOpenedResult result)
            {
                try
                {
                    System.Console.WriteLine("OneSignal Notification opened: {0}", result.notification.payload.body);

                    Dictionary <string, object>         additionalData = result.notification.payload.additionalData;
                    List <Dictionary <string, object> > actionButtons  = result.notification.payload.actionButtons;

                    if (additionalData.Count > 0)
                    {
                        System.Console.WriteLine("additionalData: {0}", additionalData);
                    }

                    if (actionButtons.Count > 0)
                    {
                        System.Console.WriteLine("actionButtons: {0}", actionButtons);
                    }
                }
                catch (System.Exception e)
                {
                    System.Console.WriteLine(e.StackTrace);
                }
            };

            // Initialize OneSignal
            OneSignal.StartInit("b2f7f966-d8cc-11e4-bed1-df8f05be55ba")
            .HandleNotificationReceived(exampleNotificationReceivedDelegate)
            .HandleNotificationOpened(exampleNotificationOpenedDelegate)
            .InFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
            .Settings(new Dictionary <string, bool> {
                { OneSignal.kOSSettingsKeyAutoPrompt, true }, { OneSignal.kOSSettingsKeyInAppLaunchURL, false }
            })
            .EndInit();

            OneSignal.IdsAvailable((playerID, pushToken) =>
            {
                try
                {
                    System.Console.WriteLine("Player ID: " + playerID);
                    if (pushToken != null)
                    {
                        System.Console.WriteLine("Push Token: " + pushToken);
                    }
                }
                catch (System.Exception e)
                {
                    System.Console.WriteLine(e.StackTrace);
                }
            });

            return(true);
        }
Exemple #7
0
 public static void Init(string appId, string launchArgs, OneSignal.NotificationReceived inNotificationDelegate = null)
 {
     OneSignal.Init(appId, launchArgs, inNotificationDelegate, new ExternalInitCordovaInternal());
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            OneSignal.NotificationReceived exampleNotificationReceivedDelegate = delegate(OSNotification notification)
            {
                try
                {
                    System.Console.WriteLine("OneSignal Notification Received:\nMessage: {0}", notification.payload.body);
                    Dictionary <string, object> additionalData = notification.payload.additionalData;

                    if (additionalData.Count > 0)
                    {
                        System.Console.WriteLine("additionalData: {0}", additionalData);
                    }
                }
                catch (System.Exception e)
                {
                    System.Console.WriteLine(e.StackTrace);
                }
            };

            // Notification Opened Delegate
            OneSignal.NotificationOpened exampleNotificationOpenedDelegate = delegate(OSNotificationOpenedResult result)
            {
                try
                {
                    System.Console.WriteLine("OneSignal Notification opened:\nMessage: {0}", result.notification.payload.body);
                    Dictionary <string, object> additionalData = result.notification.payload.additionalData;
                    if (additionalData.Count > 0)
                    {
                        System.Console.WriteLine("additionalData: {0}", additionalData);
                    }


                    List <Dictionary <string, object> > actionButtons = result.notification.payload.actionButtons;
                    if (actionButtons.Count > 0)
                    {
                        System.Console.WriteLine("actionButtons: {0}", actionButtons);
                    }
                }
                catch (System.Exception e)
                {
                    System.Console.WriteLine(e.StackTrace);
                }
            };

            // Initialize OneSignal
            OneSignal.StartInit("b2f7f966-d8cc-11e4-bed1-df8f05be55ba")
            .HandleNotificationReceived(exampleNotificationReceivedDelegate)
            .HandleNotificationOpened(exampleNotificationOpenedDelegate)
            .InFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
            .Settings(new Dictionary <string, bool> {
                { OneSignal.kOSSettingsKeyAutoPrompt, true }, { OneSignal.kOSSettingsKeyInAppLaunchURL, false }
            })
            .EndInit();

            OneSignal.IdsAvailable((playerID, pushToken) =>
            {
                try
                {
                    System.Console.WriteLine("Player ID: " + playerID);
                    if (pushToken != null)
                    {
                        System.Console.WriteLine("Push Token: " + pushToken);
                    }
                }
                catch (System.Exception e)
                {
                    System.Console.WriteLine(e.StackTrace);
                }
            });

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById <Button> (Resource.Id.myButton);

            button.Click += delegate {
                button.Text = string.Format("{0} clicks!", count++);
            };
        }
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            // Notification Receive Delegate
            OneSignal.NotificationReceived exampleNotificationReceivedDelegate = delegate(OSNotification notification)
            {
                try
                {
                    System.Console.WriteLine("OneSignal Notification Received:\nMessage: {0}", notification.payload.body);
                    Dictionary <string, object> additionalData = notification.payload.additionalData;

                    if (additionalData.Count > 0)
                    {
                        System.Console.WriteLine("additionalData: {0}", additionalData);
                    }
                }
                catch (System.Exception e)
                {
                    System.Console.WriteLine(e.StackTrace);
                }
            };

            // Notification Opened Delegate
            OneSignal.NotificationOpened exampleNotificationOpenedDelegate = delegate(OSNotificationOpenedResult result)
            {
                try
                {
                    System.Console.WriteLine("OneSignal Notification opened:\nMessage: {0}", result.notification.payload.body);
                    Dictionary <string, object> additionalData = result.notification.payload.additionalData;
                    if (additionalData.Count > 0)
                    {
                        System.Console.WriteLine("additionalData: {0}", additionalData);
                    }


                    List <Dictionary <string, object> > actionButtons = result.notification.payload.actionButtons;
                    if (actionButtons.Count > 0)
                    {
                        System.Console.WriteLine("actionButtons: {0}", actionButtons);
                    }
                }
                catch (System.Exception e)
                {
                    System.Console.WriteLine(e.StackTrace);
                }
            };

            // Initialize OneSignal
            OneSignal.StartInit("f8b5ffe8-33e3-47de-b0bc-c7fe05325f80",
                                "211973902557")
            .HandleNotificationReceived(exampleNotificationReceivedDelegate)
            .HandleNotificationOpened(exampleNotificationOpenedDelegate)
            .EndInit();

            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());
        }