Exemple #1
0
        public static UIUserNotificationSettings GetSettingsForTypes(UIUserNotificationType types)
        {
            //NOTE: right now we don't have support for categories, it required UIUserNotificationCategory, which is a somewhat advanced scenario I'd say
            IntPtr handle = ObjC.MessageSendIntPtr(_classHandle, Selector.GetHandle("settingsForTypes:categories:"), (uint)types, IntPtr.Zero);

            return(Runtime.GetNSObject <UIUserNotificationSettings>(handle));
        }
Exemple #2
0
        public IOSNotificationService()
        {
            // UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
            if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
            {
                // iOS 10 or later
                UNAuthorizationOptions authOptions =
                    UNAuthorizationOptions.Alert
                    | UNAuthorizationOptions.Badge
                    | UNAuthorizationOptions.Sound;
                UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => {
                    _hasNotificationsPermission = granted;
                    Console.WriteLine(granted);
                });

                // For iOS 10 display notification (sent via APNS)
                UNUserNotificationCenter.Current.Delegate = new IOSNotificationReceiver();

                // For iOS 10 data message (sent via FCM)
                //Messaging.SharedInstance.RemoteMessageDelegate = this;
            }
            else
            {
                // iOS 9 or before
                UIUserNotificationType allNotificationTypes =
                    UIUserNotificationType.Alert |
                    UIUserNotificationType.Badge |
                    UIUserNotificationType.Sound;
                var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
                UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
            }
        }
        public override void RegisterForRemoteNotifications(string senderId, RemoteNotificationType[] types)
        {
            SystemLogger.Log(SystemLogger.Module.PLATFORM, "Registering senderId [" + senderId + "] for receiving  push notifications");

            UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.None;
                try {
                    if (types != null)
                    {
                        SystemLogger.Log(SystemLogger.Module.PLATFORM, "Remote Notifications types enabled #num : " + types.Length);
                        foreach (RemoteNotificationType notificationType in types)
                        {
                            notificationTypes = notificationTypes | rnTypes[notificationType];
                        }
                    }

                    SystemLogger.Log(SystemLogger.Module.PLATFORM, "Remote Notifications types enabled: " + notificationTypes);
                    if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                    {
                        UIUserNotificationType uiUserNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
                        var settings = UIUserNotificationSettings.GetSettingsForTypes(uiUserNotificationTypes, new NSSet(new string[] {}));
                        UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
                    }
                    else
                    {
                        //This tells our app to go ahead and ask the user for permission to use Push Notifications
                        // You have to specify which types you want to ask permission for
                        // Most apps just ask for them all and if they don't use one type, who cares
                        UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
                    }
                } catch (Exception e) {
                    SystemLogger.Log(SystemLogger.Module.PLATFORM, "Exception ocurred: " + e.Message);
                }
            });
        }
Exemple #4
0
        public void Regist()
        {
            if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
            {
                // 許可をもらう通知タイプの種類を定義
                UNAuthorizationOptions types = UNAuthorizationOptions.Badge | // アイコンバッチ
                                               UNAuthorizationOptions.Sound | // サウンド
                                               UNAuthorizationOptions.Alert;  // テキスト

                UNUserNotificationCenter.Current.RequestAuthorization(types, (granted, err) => {
                    // Handle approval
                    if (err != null)
                    {
                        System.Diagnostics.Debug.WriteLine(err.LocalizedFailureReason + System.Environment.NewLine + err.LocalizedDescription);
                    }
                    if (granted)
                    {
                    }
                });
            }
            else                                                              //iOS9まで向け
                                                                              // 許可をもらう通知タイプの種類を定義
            {
                UIUserNotificationType types = UIUserNotificationType.Badge | // アイコンバッチ
                                               UIUserNotificationType.Sound | // サウンド
                                               UIUserNotificationType.Alert;  // テキスト
                                                                              // UIUserNotificationSettingsの生成
                UIUserNotificationSettings nSettings = UIUserNotificationSettings.GetSettingsForTypes(types, null);
                // アプリケーションに登録
                UIApplication.SharedApplication.RegisterUserNotificationSettings(nSettings);
            }
        }
 public void Register()
 {
     UIApplication.SharedApplication.InvokeOnMainThread(() =>
     {
         if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
         {
             UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Badge, (approved, err) =>
             {
                 if (approved)
                 {
                     UIApplication.SharedApplication.InvokeOnMainThread(() =>
                     {
                         UIApplication.SharedApplication.RegisterForRemoteNotifications();
                     });
                 }
             });
         }
         else if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
         {
             UIUserNotificationType userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
             UIUserNotificationSettings settings          = UIUserNotificationSettings.GetSettingsForTypes(userNotificationTypes, null);
             UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
         }
         else
         {
             UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
             UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
         }
     });
 }
Exemple #6
0
        public static void RegisterForPush()
        {
            const UIUserNotificationType notificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
            var settings = UIUserNotificationSettings.GetSettingsForTypes(notificationTypes, new NSSet());

            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
            UIApplication.SharedApplication.RegisterForRemoteNotifications();
        }
Exemple #7
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Create a Accept action
            UIMutableUserNotificationAction acceptAction = new UIMutableUserNotificationAction()
            {
                Identifier             = "ACCEPT_ID",
                Title                  = "Accept",
                ActivationMode         = UIUserNotificationActivationMode.Background,
                Destructive            = false,
                AuthenticationRequired = false
            };

            // Create a Reply action
            UIMutableUserNotificationAction replyAction = new UIMutableUserNotificationAction()
            {
                Identifier             = "REPLY_ID",
                Title                  = "Reply",
                ActivationMode         = UIUserNotificationActivationMode.Foreground,
                Destructive            = false,
                AuthenticationRequired = true
            };

            // Create a Trash action
            UIMutableUserNotificationAction trashAction = new UIMutableUserNotificationAction()
            {
                Identifier             = "TRASH_ID",
                Title                  = "Trash",
                ActivationMode         = UIUserNotificationActivationMode.Background,
                Destructive            = true,
                AuthenticationRequired = true
            };

            // Create MonkeyMessage Category
            UIMutableUserNotificationCategory monkeyMessageCategory = new UIMutableUserNotificationCategory();

            monkeyMessageCategory.Identifier = "MONKEYMESSAGE_ID";
            monkeyMessageCategory.SetActions(new UIUserNotificationAction[] { acceptAction, replyAction, trashAction }, UIUserNotificationActionContext.Default);
            monkeyMessageCategory.SetActions(new UIUserNotificationAction[] { acceptAction, trashAction }, UIUserNotificationActionContext.Minimal);

            // Create a category group
            NSSet categories = new NSSet(monkeyMessageCategory);

            // Set the requested notification types
            UIUserNotificationType type = UIUserNotificationType.Alert | UIUserNotificationType.Badge;

            // Create the setting for the given types
            UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes(type, categories);

            // Register the settings
            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);

            //Completed
            return(true);
        }
Exemple #8
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // Initialize the Parse client with your Application ID and Windows Key found on
            // your Parse dashboard
            // PARSE INTERNAL
            // To properly scrub this project for public release, the following changes must be made:
            // 1. This region should be replaced with a template Parse.Initialize call.
            // 2. The project must stop requesting intranet permission.
            // 3. The project may not access Parse.snk, or it will retain access to Parse internals.
            // 4. We must verify that Parse.snk is never copied to this project directory by msbuild.
            //ParseClient.HostName = new Uri("http://parse-local:3000/")
            ParseClient.Initialize("ZIqbEBf3PXXSzpbQbvz5BcmVcK54DjSmKwNxCah1", "EY4UfiJn0xGhvgvNhBRrY6kggn4nv9zGGk5klQQo");
            // END PARSE INTERNAL

            // Register for remote notifications
            if (Convert.ToInt16(UIDevice.CurrentDevice.SystemVersion.Split('.')[0].ToString()) < 8)
            {
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
            }
            else
            {
                UIUserNotificationType notificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
                var settings = UIUserNotificationSettings.GetSettingsForTypes(notificationTypes, new NSSet(new string[] { }));
                UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
                UIApplication.SharedApplication.RegisterForRemoteNotifications();
            }

            // Handle Parse Push notification.
            ParsePush.ParsePushNotificationReceived += (object sender, ParsePushNotificationEventArgs args) => {
                Console.WriteLine("You received a notification!");
            };

            // create a new window instance based on the screen size
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            UIViewController viewController = new UIViewController();
            UILabel          label          = new UILabel(new CoreGraphics.CGRect(0, 0, 160, 20));

            label.Text      = "Parse Push is ready!";
            label.TextColor = UIColor.Gray;
            label.Center    = viewController.View.Center;
            viewController.Add(label);
            window.BackgroundColor = UIColor.White;
            // If you have defined a view, add it here:
            window.RootViewController = viewController;
            window.MakeKeyAndVisible();

            return(true);
        }
 public void Register()
 {
     if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
     {
         UIUserNotificationType     userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
         UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes(userNotificationTypes, null);
         UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
     }
     else
     {
         UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
         UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
     }
 }
Exemple #10
0
        public bool CheckPermission(string permission)
        {
            switch (permission)
            {
            case "IOS.permission.LOCATION":
                //application dont need location per below ios 8.0
                if (!(UIDevice.CurrentDevice.CheckSystemVersion(8, 0)))
                {
                    return(true);
                }

                switch (CLLocationManager.Status)
                {
                case CLAuthorizationStatus.Authorized:
                    return(true);

                //break;
                case CLAuthorizationStatus.AuthorizedWhenInUse:
                    return(true);

                //break;
                case CLAuthorizationStatus.Denied:
                    return(false);

                //break;
                case CLAuthorizationStatus.NotDetermined:
                    return(false);
                    //break;
                }
                break;

            case "IOS.permission.NOTIFICATION":

                if (!(UIDevice.CurrentDevice.CheckSystemVersion(10, 0)))
                {
                    return(false);
                }

                UIUserNotificationType types = UIApplication.SharedApplication.CurrentUserNotificationSettings.Types;

                if (types.HasFlag(UIUserNotificationType.Alert) /*|| types.HasFlag(UIUserNotificationType.Badge) || types.HasFlag(UIUserNotificationType.Sound)*/)
                {
                    return(true);
                }
                return(false);
                //break;
            }
            return(false);
        }
Exemple #11
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            UNUserNotificationCenter.Current.Delegate = new MyNotificationDelegate();
            global::Xamarin.Forms.Forms.Init();
            global::ZXing.Net.Mobile.Forms.iOS.Platform.Init();

            Xamarin.FormsMaps.Init();

            var thai = new System.Globalization.ThaiBuddhistCalendar();

            var en = new System.Globalization.CultureInfo("en-US");

            System.Threading.Thread.CurrentThread.CurrentCulture = en;

            //if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            //{
            //    var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(
            //        UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null
            //    );

            //    UIApplication.SharedApplication.RegisterUserNotificationSettings(notificationSettings);
            //}

            //UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;

            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                UIUserNotificationType     userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
                UIUserNotificationSettings notificationSettings  = UIUserNotificationSettings.GetSettingsForTypes(userNotificationTypes, null);
                UIApplication.SharedApplication.RegisterUserNotificationSettings(notificationSettings);
                UIApplication.SharedApplication.RegisterForRemoteNotifications();
            }
            else
            {
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
            }

            AppCenter.Start("3e99bed8-99b8-4485-80ce-86d2a93649ef", typeof(Analytics), typeof(Crashes));
            AppCenter.Start("3e99bed8-99b8-4485-80ce-86d2a93649ef", typeof(Push));

            LoadApplication(new App());

            UIApplication.SharedApplication.BeginBackgroundTask(() => {});

            UIApplication.SharedApplication.IdleTimerDisabled = true;

            return(base.FinishedLaunching(app, options));
        }
Exemple #12
0
        public void RegisterForPushNotifications()
        {
            this.ExecuteMethodOnMainThread("RegisterForPushNotifications", delegate()
            {
                bool isAppetize = NSUserDefaults.StandardUserDefaults.BoolForKey("isAppetize");
                if (isAppetize)
                {
                    return;
                }

                UIUserNotificationType types        = UIUserNotificationType.Sound | UIUserNotificationType.Badge | UIUserNotificationType.Alert;
                UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes(types, null);
                UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
            });
        }
 void RegisterNotifications(UIUserNotificationType notifications, UIRemoteNotificationType remoteNotification)
 {
     if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
     {
         if (!notificationTypes.HasFlag(notifications))
         {
             notificationTypes |= notifications;
             var settings = UIUserNotificationSettings.GetSettingsForTypes(notificationTypes, null);
             UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
         }
     }
     else if (!remoteNotificationTypes.HasFlag(remoteNotification))
     {
         remoteNotificationTypes |= remoteNotification;
         UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(remoteNotificationTypes);
     }
 }
Exemple #14
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // create a new window instance based on the screen size
            window = new UIWindow(UIScreen.MainScreen.Bounds);
            UINavigationBar.Appearance.BackgroundColor = UIColor.FromRGBA(0, 0, 0, 0);
            UINavigationBar.Appearance.TintColor       = UIColor.White;
            UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes()
            {
                Font      = UIFont.FromName(PostItController.FontLightName, 20f),
                TextColor = UIColor.White
            });
            UIButton.Appearance.TintColor = UIColor.White;

            // If you have defined a root view controller, set it here:
            // window.RootViewController = myViewController;
            postItController          = new PostItController();
            navigation                = new UINavigationController(postItController);
            window.RootViewController = navigation;
            // make the window visible
            window.MakeKeyAndVisible();

            // check for a notification
            if (options != null)
            {
                // check for a local notification
                if (options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
                {
                    var localNotification = options[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
                    if (localNotification != null)
                    {
                        ProcessNotification(localNotification);
                    }
                }
            }

            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                const UIUserNotificationType notificationUserTypes = UIUserNotificationType.Alert;
                UIUserNotificationSettings   notificationSettings  = UIUserNotificationSettings.GetSettingsForTypes(notificationUserTypes, null);
                UIApplication.SharedApplication.RegisterUserNotificationSettings(notificationSettings);
            }

            return(true);
        }
Exemple #15
0
        public void Register()
        {
            if (!CrossPushNotification.IsInitialized)
            {
                throw NewPushNotificationNotInitializedException();
            }

            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                UIUserNotificationType     userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
                UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes(userNotificationTypes, null);
                UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
            }
            else
            {
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
            }
        }
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // Initialize the Parse client with your Application ID and Windows Key found on
            // your Parse dashboard
            ParseClient.Initialize("YOUR APPLICATION ID", "YOUR .NET KEY");

            // Register for remote notifications
            if (Convert.ToInt16(UIDevice.CurrentDevice.SystemVersion.Split('.')[0].ToString()) < 8)
            {
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
            }
            else
            {
                UIUserNotificationType notificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
                var settings = UIUserNotificationSettings.GetSettingsForTypes(notificationTypes, new NSSet(new string[] { }));
                UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
                UIApplication.SharedApplication.RegisterForRemoteNotifications();
            }

            // Handle Parse Push notification.
            ParsePush.ParsePushNotificationReceived += (object sender, ParsePushNotificationEventArgs args) => {
                Console.WriteLine("You received a notification!");
            };

            // create a new window instance based on the screen size
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            UIViewController viewController = new UIViewController();
            UILabel          label          = new UILabel(new CoreGraphics.CGRect(0, 0, 160, 20));

            label.Text      = "Parse Push is ready!";
            label.TextColor = UIColor.Gray;
            label.Center    = viewController.View.Center;
            viewController.Add(label);
            window.BackgroundColor = UIColor.White;
            // If you have defined a view, add it here:
            window.RootViewController = viewController;
            window.MakeKeyAndVisible();

            return(true);
        }
Exemple #17
0
        private void ParsePushInitialize()
        {
            // Register for Push Notitications
            UIUserNotificationType notificationTypes = (UIUserNotificationType.Alert |
                                                        UIUserNotificationType.Badge |
                                                        UIUserNotificationType.Sound);
            var settings = UIUserNotificationSettings.GetSettingsForTypes(notificationTypes,
                                                                          new NSSet(new string[] { }));

            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
            UIApplication.SharedApplication.RegisterForRemoteNotifications();

            ParsePush.ParsePushNotificationReceived += (object sender, ParsePushNotificationEventArgs args) =>
            {
                if (args.Payload.ContainsKey("alert"))
                {
                    //args.Payload["alert"].ToString();
                }
            };
        }
Exemple #18
0
        public override void ViewWillDisappear(bool animated)
        {
            base.ViewWillDisappear(animated);

            if (notifications.Value && !Settings.Notifications)
            {
                if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                {
                    const UIUserNotificationType notificationUserTypes = UIUserNotificationType.Alert;
                    UIUserNotificationSettings   notificationSettings  = UIUserNotificationSettings.GetSettingsForTypes(notificationUserTypes, null);
                    UIApplication.SharedApplication.RegisterUserNotificationSettings(notificationSettings);
                }
            }

            Settings.Twitter       = twitter.Value;
            Settings.Facebook      = facebook.Value;
            Settings.Sina          = sina.Value;
            Settings.Tencent       = tencent.Value;
            Settings.Color         = color.Selected;
            Settings.Notifications = notifications.Value;
        }
        public void RegisterForNotifications(bool showAlert, bool showBadge, bool playSound)
        {
            UIUserNotificationType notificationType = UIUserNotificationType.None;

            if (showAlert)
            {
                notificationType |= UIUserNotificationType.Alert;
            }

            if (showBadge)
            {
                notificationType |= UIUserNotificationType.Badge;
            }

            if (playSound)
            {
                notificationType |= UIUserNotificationType.Sound;
            }

            var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(notificationType, null);

            UIApplication.SharedApplication.RegisterUserNotificationSettings(notificationSettings);
        }
 public static UIUserNotificationSettings GetSettingsForTypes(UIUserNotificationType types)
 {
     return(Runtime.GetNSObject <UIUserNotificationSettings>(ObjC.MessageSendIntPtr(_classHandle, Selector.GetHandle("settingsForTypes:categories:"), (uint)types, IntPtr.Zero)));
 }
Exemple #21
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            // Code to start the Xamarin Test Cloud Agent
            const string APPLICATION_ID = "G7S25vITx0tfeOhODauYKwtauCvzityLwJFGYHPw";
            const string DOT_NET_ID     = "ypPxS2V2rTGl1lNbvEVKUEACKF8PRhWxkWQsbkFe";

            //ParseClient.Initialize(new ParseClient.Configuration
            //{
            //	ApplicationId = APPLICATION_ID,
            //	WindowsKey = DOT_NET_ID,
            //	Server = "https://parseapi.back4app.com"
            //});
            ParseClient.Initialize(APPLICATION_ID, DOT_NET_ID);

            ////Register for remote notifications.
            if (Convert.ToInt16(UIDevice.CurrentDevice.SystemVersion.Split('.')[0]) < 8)
            {
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
            }
            else
            {
                UIUserNotificationType notificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
                var settings = UIUserNotificationSettings.GetSettingsForTypes(notificationTypes, null);
                UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
                UIApplication.SharedApplication.RegisterForRemoteNotifications();
            }

            //Handle Parse Push notifications.

            ParsePush.ParsePushNotificationReceived += (sender, e) =>
            {
                IDictionary <string, object> payload = e.Payload;
                object aps;

                if (payload.TryGetValue("aps", out aps))
                {
                    NSDictionary dictionary = aps as NSDictionary;

                    foreach (var elements in dictionary)
                    {
                        string value = elements.Value.ToString();

                        if (value.Contains("New"))
                        {
                            //App Admin side handles notification
                            //string[] splitArr = value.Split(' ');
                            //string channelName = splitArr[3] + splitArr[4];


                            var refreshAdminTable = (Window.RootViewController as UINavigationController).TopViewController as AdminViewController;
                            refreshAdminTable.AddOrders();

                            //var adminOrders = new AdminViewController(channelName);
                            //adminOrders.AddNewOrders();
                            break;
                        }
                        if (value.Contains("ready!!!"))
                        {
                            UIAlertView alert = new UIAlertView();
                            alert.Title   = "Done";
                            alert.Message = "You are hooked!!!";
                            alert.AddButton("OK");
                            alert.Show();

                            Debug.WriteLine("Order ready for user");
                            //App user side handles notification
                            var refreshQueueTable = (Window.RootViewController as UINavigationController).TopViewController as QueueViewController;
                            refreshQueueTable.AddQueueOrders();
                        }
                    }
                }
            };

            Window = new UIWindow(UIScreen.MainScreen.Bounds);
            UIViewController       loginController      = new LoginViewController();
            UINavigationController navigationController = new UINavigationController(loginController);

            Window.RootViewController = navigationController;
            Window.MakeKeyAndVisible();

            return(true);
        }
Exemple #22
0
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            try {
                // dependency
                Xamarin.Forms.DependencyService.Register <Model.IOSCookieStore>();
                Xamarin.Forms.DependencyService.Register <Model.Notification>();

                global::Xamarin.Forms.Forms.Init();
                LoadApplication(new App());

                Xam.Plugin.WebView.iOS.FormsWebViewRenderer.Initialize();
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                // Notification settings
                if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                {
                    UIUserNotificationType     userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
                    UIUserNotificationSettings notificationSettings  = UIUserNotificationSettings.GetSettingsForTypes(userNotificationTypes, null);
                    UIApplication.SharedApplication.RegisterUserNotificationSettings(notificationSettings);
                    UIApplication.SharedApplication.RegisterForRemoteNotifications();
                }
                else
                {
                    UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
                    UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
                }

                // Check for notifications
                if (options != null)
                {
                    // Check for local notification
                    if (options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
                    {
                        var localNotification = options[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
                        if (localNotification != null)
                        {
                            UIAlertController okayAlertController = UIAlertController.Create(localNotification.AlertAction, localNotification.AlertBody, UIAlertControllerStyle.Alert);
                            okayAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));

                            Window.RootViewController.PresentViewController(okayAlertController, true, null);

                            // reset our badge
                            UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
                        }
                    }

                    // Check for remote notification
                    if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
                    {
                        NSDictionary remoteNotification = (NSDictionary)options[UIApplication.LaunchOptionsRemoteNotificationKey];
                        if (remoteNotification != null)
                        {
                            //NotificationHelper.processNotification(userInfo, true, false);
                        }
                    }
                }

                return(base.FinishedLaunching(app, options));
            } catch (Exception ex) {
                Console.WriteLine("Domain Exception from  {0}", ex.ToString());
            }

            return(true);
        }
 public UIUserNotificationSettings(UIUserNotificationType forTypes, [Optional] NSSet categories)
 {
 }
 public static UIUserNotificationSettings GetSettingsForTypes(UIUserNotificationType types)
 {
     //NOTE: right now we don't have support for categories, it required UIUserNotificationCategory, which is a somewhat advanced scenario I'd say
     IntPtr handle = ObjC.MessageSendIntPtr(_classHandle, "settingsForTypes:categories:", (uint)types, IntPtr.Zero);
     return Runtime.GetNSObject<UIUserNotificationSettings>(handle);
 }