예제 #1
0
        private void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
        {
            // check for a notification
            if (options != null)
            {
                // check for a local notification
                if (options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
                {
                    Debug.WriteLine("Local notification recieved");
                    ProcessLocalNotification(options);
                    return;
                }

                // Check for push notification
                if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
                {
                    options = options.GetTypeValueFromOptions <NSDictionary>(UIApplication.LaunchOptionsRemoteNotificationKey);
                }

                if (options.ContainsKey(new NSString("aps")))
                {
                    Debug.WriteLine("Push notification recieved");
                    ProcessPushNotification(options, fromFinishedLaunching);
                    return;
                }

                Debug.WriteLine($"Notification recieved but is not a local and does not contain 'aps' signature, first entry : {options.First()}");
            }
            else
            {
                Debug.WriteLine("Process notification options = null");
            }
        }
예제 #2
0
        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action <UIBackgroundFetchResult> completionHandler)
        {
            NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;

            // The aps is a dictionary with the template values in it
            // You can adjust this section to do whatever you need to with the push notification

            string alert = string.Empty;

            if (aps.ContainsKey(new NSString("alert")))
            {
                alert = (aps[new NSString("alert")] as NSString).ToString();
            }

            string badge = string.Empty;

            if (aps.ContainsKey(new NSString("badge")))
            {
                badge = (aps[new NSString("badge")] as NSNumber).ToString();
            }

            string payload = string.Empty;

            if (aps.ContainsKey(new NSString("payload")))
            {
                payload = (aps[new NSString("payload")] as NSString).ToString();
            }

            var payloadData = JsonConvert.DeserializeObject <NotificationPayload>(payload);

            DisplayAlert("Success", alert + " " + badge);
        }
        /// <summary>
        /// Call this method from the ReceivedRemoteNotification override into the AppDelegate to register for notifications
        /// </summary>
        /// <param name="notificationService">This notification service</param>
        /// <param name="userInfo">User info received</param>
        /// <exception cref="ArgumentNullException">userInfo should not be null</exception>
        public static void ReceivedRemoteNotification(this IAptkAmaNotificationService notificationService, NSDictionary userInfo)
        {
            if (userInfo == null)
            {
                throw new ArgumentNullException(nameof(userInfo));
            }

            if (!userInfo.ContainsKey(new NSString("aps")) &&
                userInfo.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey) &&
                (userInfo = userInfo.ObjectForKey(UIApplication.LaunchOptionsRemoteNotificationKey) as NSDictionary) == null)
            {
                return;
            }

            var platformNotificationService = notificationService as AptkAmaNotificationService;

            if (platformNotificationService?.Configuration?.NotificationHandler == null)
            {
                throw new NullReferenceException("NotificationHandler could not be null when working with notifications");
            }

            var notification = (userInfo.ObjectForKey(new NSString("aps")) as NSDictionary)?.ToDictionary(n => n.Key.ToString(), n => n.Value.ToObject()).ToNotification();

            if (notification == null)
            {
                Debug.WriteLine($"Notification convertion failed for: {userInfo}");
                return;
            }

            Debug.WriteLine($"Notification received: {JsonConvert.SerializeObject(notification)}");

            UIApplication.SharedApplication.InvokeOnMainThread(() => platformNotificationService.Configuration.NotificationHandler.OnNotificationReceived(notification));
        }
예제 #4
0
        private void ProcessNotification(NSDictionary options, bool showAlert)
        {
            if (null != options && options.ContainsKey(new NSString("aps")))
            {
                NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;

                string title = string.Empty;
                string body  = string.Empty;

                if (aps != null && aps.ContainsKey(new NSString("alert")))
                {
                    title = (aps[new NSString("alert")] as NSString)?.ToString();
                }

                if (aps != null && aps.ContainsKey(new NSString("body")))
                {
                    body = aps[new NSString("body")].ToString();
                }


                if (showAlert)
                {
                    if (!string.IsNullOrEmpty(body) || !string.IsNullOrEmpty(title))
                    {
                        var avAlert = new UIAlertView(title, body, null, "Ok", null);
                        avAlert.Show();
                    }
                }
            }
        }
예제 #5
0
        void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
        {
            if (null != options && options.ContainsKey(new NSString("aps")))
            {
                NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;

                string subject = string.Empty;
                string message = string.Empty;

                if (aps.ContainsKey(new NSString("subject")) && aps.ContainsKey(new NSString("message")))
                {
                    subject = (aps[new NSString("subject")] as NSString).ToString();
                    message = (aps[new NSString("message")] as NSString).ToString();

                    //If this came from the ReceivedRemoteNotification while the app was running,
                    // we of course need to manually process things like the sound, badge, and alert.
                    if (!fromFinishedLaunching)
                    {
                        //Manually show an alert
                        if (!string.IsNullOrEmpty(subject) && !string.IsNullOrEmpty(message))
                        {
                            UIAlertView avAlert = new UIAlertView(subject, message, null, "OK", null);
                            avAlert.Show();
                        }
                    }
                }
            }
        }
예제 #6
0
        public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
        {
            NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;

            if (aps.ContainsKey(new NSString("alert")))
            {
                NSDictionary alertPayload = aps.ObjectForKey(new NSString("alert")) as NSDictionary;


                string alertMessage = string.Empty;
                string title        = string.Empty;

                if (alertPayload.ContainsKey(new NSString("title")))
                {
                    title = (alertPayload[new NSString("title")] as NSString).ToString();
                }

                if (alertPayload.ContainsKey(new NSString("body")))
                {
                    alertMessage = (alertPayload[new NSString("body")] as NSString).ToString();
                }


                //show alert
                var alert = UIAlertController.Create(title, alertMessage, UIAlertControllerStyle.Alert);
                alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, null));
                UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alert, true, null);
            }
        }
예제 #7
0
        protected void ProcessNotifications(NSDictionary data, bool fromBackground)
        {
            base.ExecuteMethod("ProcessNotifications", delegate()
            {
                if (data.ContainsKey(nsAps))
                {
                    NSDictionary apsDictionary = data[nsAps] as NSDictionary;

                    // process badge
                    this.ProcessNotification_Badge(fromBackground, apsDictionary);

                    // Process Others
                    NSDictionary alertDictionary = apsDictionary[nsAlert] as NSDictionary;

                    if (data.ContainsKey(nsSample))
                    {
                        this.ProcessNotification_Sample(fromBackground, data, apsDictionary, alertDictionary);
                    }
                    else
                    {
                        // try generic alert
                        string alertString     = string.Empty;
                        NSString alertNSString = apsDictionary[nsAlert] as NSString;
                        if (alertNSString != null)
                        {
                            alertString = alertNSString.ToString();
                        }
                        if (!string.IsNullOrEmpty(alertString))
                        {
                            ProcessNotification_Generic(fromBackground, data, alertString);
                        }
                    }
                }
            });
        }
예제 #8
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            PlatformOpenTokService.Init();
            global::Xamarin.Forms.Forms.Init();
            AiForms.Dialogs.Dialogs.Init();
            Xamarin.FormsMaps.Init();
            Xamarin.FormsGoogleMaps.Init(AppConfigurations.IosGoogleMapsAPIKey);
            App.Context = this;

            Firebase.Core.App.Configure();
            Rg.Plugins.Popup.Popup.Init();
            Plugin.InputKit.Platforms.iOS.Config.Init();

            CGRect bounds = UIScreen.MainScreen.Bounds;

            if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight)
            {
                bounds.Size = new CGSize(bounds.Size.Height, bounds.Size.Width);
            }
            activityIndicator = new UIActivityIndicator(bounds);

            string id    = null;
            string alert = null;
            string code  = null;
            string url   = string.Empty;

            if (options != null && options.Keys != null && options.Keys.Count() != 0 && options.ContainsKey(new NSString("UIApplicationLaunchOptionsRemoteNotificationKey")))
            {
                var remoteNotificationKey = options.ObjectForKey(new NSString("UIApplicationLaunchOptionsRemoteNotificationKey")) as NSDictionary;

                if (null != remoteNotificationKey && remoteNotificationKey.ContainsKey(new NSString("aps")))
                {
                    NSDictionary aps = remoteNotificationKey.ObjectForKey(new NSString("aps")) as NSDictionary;

                    if (aps.ContainsKey(new NSString("id")))
                    {
                        id = (aps[new NSString("id")] as NSString).ToString();
                    }

                    if (aps.ContainsKey(new NSString("alert")))
                    {
                        alert = (aps[new NSString("alert")] as NSString).ToString();
                    }

                    if (aps.ContainsKey(new NSString("code")))
                    {
                        code = (aps[new NSString("code")] as NSString).ToString();
                    }

                    if (aps.ContainsKey(new NSString("Url")))
                    {
                        url = (aps[new NSString("Url")] as NSString).ToString();
                    }
                }
            }

            LoadApplication(new App(id, alert, code, url));

            return(base.FinishedLaunching(app, options));
        }
예제 #9
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary options)
        {
            if (options != null)
            {
                if (options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
                {
                    // was woken from Local notification
                    var localNotification =
                        options[UIApplication.LaunchOptionsLocalNotificationKey] as
                        UILocalNotification;

                    if (localNotification != null)
                    {
                        ReceivedLocalNotification(localNotification);
                    }
                }
                else if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
                {
                    var remoteNotification =
                        options[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;

                    if (remoteNotification != null)
                    {
                        ReceivedRemoteNotification(remoteNotification);
                    }
                }
            }

            return(true);
        }
예제 #10
0
        /// <summary>
        /// App was closed but received notification
        /// </summary>
        /// <param name="options">Options.</param>
        protected internal void HandleNotification(NSDictionary options)
        {
            if (options != null)
            {
                // check for a local notification
                if (options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
                {
                    UILocalNotification localNotification = options[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
                    if (localNotification != null)
                    {
                        // TODO: Local Notification received. Do something with it
                        new UIAlertView(localNotification.AlertAction, localNotification.AlertBody, null, "OK", null).Show();
                    }
                }

                // check for a remote notification
                if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
                {
                }
                else
                {
                    // TODO: remote notification received
                }
            }
        }
예제 #11
0
        public static Font ToSDFont(this NSFont font, NSDictionary attributes = null)
        {
            var descriptor = font.FontDescriptor;
            var traits     = (NSFontTraitMask)descriptor.SymbolicTraits;
            var style      = (FontStyle)0;

            if (0 != (traits & NSFontTraitMask.Bold))
            {
                style |= FontStyle.Bold;
            }
            if (0 != (traits & NSFontTraitMask.Italic))
            {
                style |= FontStyle.Italic;
            }

            if (attributes != null)
            {
                if (attributes.ContainsKey(AttributeKeys.NSStrikethrough))
                {
                    style |= FontStyle.Strikeout;
                }
                if (attributes.ContainsKey(AttributeKeys.NSUnderline))
                {
                    style |= FontStyle.Underline;
                }
            }

            var ptSize = (float)font.PointSize * 72f / 96f;             // Apple points to rest-of-the-world points

            return(new Font(font.FamilyName, ptSize, style, GraphicsUnit.Point));
        }
예제 #12
0
        /// <summary>
        /// Tos the local notification.
        /// </summary>
        /// <returns>The local notification.</returns>
        /// <param name="userInfo">User info.</param>
        public static LocalNotification ToLocalNotification(this NSDictionary userInfo)
        {
            var notification = new LocalNotification();

            if (null != userInfo && userInfo.ContainsKey(new NSString("aps")))
            {
                NSDictionary aps   = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
                NSDictionary alert = null;
                if (aps.ContainsKey(new NSString("alert")))
                {
                    alert = aps.ObjectForKey(new NSString("alert")) as NSDictionary;
                }
                if (alert != null)
                {
                    notification.Title    = (alert[new NSString("title")] as NSString).ToString();
                    notification.SubTitle = (alert[new NSString("subtitle")] as NSString).ToString();
                    notification.Message  = (alert[new NSString("body")] as NSString).ToString();
                    if (aps.ContainsKey(new NSString("badge")))
                    {
                        var cnt = (alert[new NSString("badge")] as NSString).ToString();
                        notification.Badge = int.Parse(cnt);
                    }
                }
            }
            return(notification);
        }
예제 #13
0
        /*public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
         * {
         *      ProcessNotification(userInfo, false);
         * }*/

        void ProcessNotification(NSDictionary options, bool fromFinishedLaunching, UIApplicationState appState)
        {
            // Check to see if the dictionary has the aps key.  This is the notification payload you would have sent
            if (null != options && options.ContainsKey(new NSString("aps")))
            {
                //Get the aps dictionary
                NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;

                string alert = string.Empty;

                //Extract the alert text
                //NOTE: If you're using the simple alert by just specifying "  aps:{alert:"alert msg here"}  "
                //this will work fine.  But if you're using a complex alert with Localization keys, etc.,
                //your "alert" object from the aps dictionary will be another NSDictionary... Basically the
                //json gets dumped right into a NSDictionary, so keep that in mind
                if (aps.ContainsKey(new NSString("alert")))
                {
                    alert = (aps [new NSString("alert")] as NSString).ToString();

                    int tripid = -1;
                    if (aps.ContainsKey(new NSString("tripid")))
                    {
                        tripid = (aps [new NSString("tripid")] as NSNumber).IntValue;
                    }


                    //If this came from the ReceivedRemoteNotification while the app was running,
                    // we of course need to manually process things like the sound, badge, and alert.
                    if (!fromFinishedLaunching)
                    {
                        //Manually show an alert
                        if (!string.IsNullOrEmpty(alert))
                        {
                            if (NotificationAlertView != null)
                            {
                                NotificationAlertView.DismissWithClickedButtonIndex(0, false);
                            }

                            GAI.SharedInstance.DefaultTracker.Send(GAIDictionaryBuilder.CreateEvent("app_action", "notifications", "alert", null).Build());

                            NotificationAlertView = new UIAlertView("Notification", alert, null, "OK", null);
                            NotificationAlertView.Show();
                        }
                    }
                }

                if (aps.ContainsKey(new NSString("content-available")))
                {
                    GAI.SharedInstance.DefaultTracker.Send(GAIDictionaryBuilder.CreateEvent("app_action", "notifications", "content-available", null).Build());
                    //TODO get list of times to send location
                    //backgroundTaskId = UIApplication.SharedApplication.BeginBackgroundTask( () => {});
                    DurationToSendLocation_Sec = (aps [new NSString("content-available")] as NSNumber).IntValue;
                    //NSTimer locationTimer = NSTimer.CreateScheduledTimer (TimeSpan.FromSeconds (60), delegate {
                    MonitorLocation(appState);
                    //});
                }
            }
        }
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			#if DEBUG
			Xamarin.Calabash.Start();
			#endif


			// create our window
			window = new UIWindow (UIScreen.MainScreen.Bounds);
			window.MakeKeyAndVisible ();

			home = new Screens.iPhone.Home.Home_iPhone();
			home.View.Frame = new CoreGraphics.CGRect (0, UIApplication.SharedApplication.StatusBarFrame.Height, UIScreen.MainScreen.ApplicationFrame.Width, UIScreen.MainScreen.ApplicationFrame.Height);
			window.RootViewController = home;

			// check for a notification
			if(options != null) {

				// check for a local notification
				if(options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey)) {

					UILocalNotification localNotification = options[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
					if(localNotification != null) {

						new UIAlertView(localNotification.AlertAction, localNotification.AlertBody, null, "OK", null).Show();
						// reset our badge
						UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
					}
				}

				// check for a remote notification
				if(options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey)) {

					NSDictionary remoteNotification = options[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
					if(remoteNotification != null) {
						//new UIAlertView(remoteNotification.AlertAction, remoteNotification.AlertBody, null, "OK", null).Show();
					}
				}
			}

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

				app.RegisterUserNotificationSettings (notificationSettings);
				app.RegisterForRemoteNotifications ();
			} else {
				//==== register for remote notifications and get the device token
				// set what kind of notification types we want
				UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge;
				// register for remote notifications
				UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
			}

			return true;
		}
예제 #15
0
        //public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
        //{
        //	CrossAzurePushNotifications.Platform.ProcessNotification(userInfo);
        //}

        //public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        //{
        //	CrossAzurePushNotifications.Platform.RegisteredForRemoteNotifications(deviceToken);
        //}

        void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
        {
            // Check to see if the dictionary has the aps key.  This is the notification payload you would have sent
            if (null != options && options.ContainsKey(new NSString("aps")))
            {
                //Get the aps dictionary
                NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;
                Console.WriteLine(aps.ToString());
                string alert = string.Empty;
                string title = string.Empty;


                if (aps.ContainsKey(new NSString("alert")))
                {
                    NSDictionary alertObj = aps.ObjectForKey(new NSString("alert")) as NSDictionary;

                    if (alertObj.ContainsKey(new NSString("body")))
                    {
                        alert = (alertObj[new NSString("body")] as NSString).ToString();
                    }
                    Console.WriteLine($"============{alert}++++++++");
                    if (alertObj.ContainsKey(new NSString("title")))
                    {
                        title = (alertObj[new NSString("title")] as NSString).ToString();
                    }
                }

                //Extract the alert text
                // NOTE: If you're using the simple alert by just specifying
                // "  aps:{alert:"alert msg here"}  ", this will work fine.
                // But if you're using a complex alert with Localization keys, etc.,
                // your "alert" object from the aps dictionary will be another NSDictionary.
                // Basically the JSON gets dumped right into a NSDictionary,
                // so keep that in mind.
                //if (aps.ContainsKey(new NSString("alert")))
                //alert = (aps[new NSString("alert")] as NSString).ToString();

                //NSDictionary alertDictionary = aps.ObjectForKey(new NSString("alert")) as NSDictionary;
                //string title = string.Empty;
                //if (alertDictionary.ContainsKey(new NSString("title")))
                //	title = (alertDictionary[new NSString("title")] as NSString).ToString();

                //If this came from the ReceivedRemoteNotification while the app was running,
                // we of course need to manually process things like the sound, badge, and alert.
                if (!fromFinishedLaunching)
                {
                    //Manually show an alert
                    if (!string.IsNullOrEmpty(alert))
                    {
                        //removed on 3/22/17 by aditmer - I think this is preventing alarms from playing.
                        //UIAlertView avAlert = new UIAlertView(title, alert, null, "OK", null);
                        //avAlert.Show();
                    }
                }
            }
        }
예제 #16
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // create our window
            window = new UIWindow(UIScreen.MainScreen.Bounds);
            window.MakeKeyAndVisible();

            home                      = new Screens.iPhone.Home.Home_iPhone();
            home.View.Frame           = new CoreGraphics.CGRect(0, UIApplication.SharedApplication.StatusBarFrame.Height, UIScreen.MainScreen.ApplicationFrame.Width, UIScreen.MainScreen.ApplicationFrame.Height);
            window.RootViewController = home;

            // check for a notification
            if (options != null)
            {
                // check for a local notification
                if (options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
                {
                    UILocalNotification localNotification = options[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
                    if (localNotification != null)
                    {
                        new UIAlertView(localNotification.AlertAction, localNotification.AlertBody, null, "OK", null).Show();
                        // reset our badge
                        UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
                    }
                }

                // check for a remote notification
                if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
                {
                    NSDictionary remoteNotification = options[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
                    if (remoteNotification != null)
                    {
                        //new UIAlertView(remoteNotification.AlertAction, remoteNotification.AlertBody, null, "OK", null).Show();
                    }
                }
            }

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

                app.RegisterUserNotificationSettings(notificationSettings);
                app.RegisterForRemoteNotifications();
            }
            else
            {
                //==== register for remote notifications and get the device token
                // set what kind of notification types we want
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge;
                // register for remote notifications
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
            }

            return(true);
        }
예제 #17
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)
        {
            // check for a notification

            if (options != null)
            {
                // check for a local notification
                if (options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
                {
                    UILocalNotification localNotification = options[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
                    if (localNotification != null)
                    {
                        new UIAlertView(localNotification.AlertAction, localNotification.AlertBody, null, "OK", null).Show();
                        // reset our badge
                        UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
                    }
                }

                // check for a remote notification
                if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
                {
                    NSDictionary remoteNotification = options[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
                    if (remoteNotification != null)
                    {
                        //new UIAlertView(remoteNotification.AlertAction, remoteNotification.AlertBody, null, "OK", null).Show();
                    }
                }
            }

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

                app.RegisterUserNotificationSettings(notificationSettings);
                app.RegisterForRemoteNotifications();
            }
            else
            {
                //==== register for remote notifications and get the device token
                // set what kind of notification types we want
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge;
                // register for remote notifications
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
            }



            WireUpLongRunningTask();

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

            return(base.FinishedLaunching(app, options));
        }
예제 #18
0
        public void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
        {
            // Check to see if the dictionary has the aps key.  This is the notification payload you would have sent
            if (null != options && options.ContainsKey(new NSString("aps")))
            {
                //Get the aps dictionary
                NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;

                string alertString  = string.Empty;
                string paramString  = string.Empty;
                string alertTitle   = string.Empty;
                string alertContent = string.Empty;

                if (aps.ContainsKey(new NSString("alert")))
                {
                    alertString = (aps[new NSString("alert")] as NSString).ToString();
                }
                if (!string.IsNullOrWhiteSpace(alertString) && alertString.Split('§').Length > 1)
                {
                    alertTitle   = alertString.Split('§')[0];
                    alertContent = alertString.Split('§')[1];
                }
                else
                {
                    alertTitle   = "RMMT";
                    alertContent = alertString;
                }

                if (aps.ContainsKey(new NSString("param")))
                {
                    paramString = (aps[new NSString("param")] as NSString).ToString();
                }

                if (!fromFinishedLaunching)
                {
                    //Manually show an alert
                    if (!string.IsNullOrWhiteSpace(alertString))
                    {
                        UIApplication.SharedApplication.BeginInvokeOnMainThread(delegate
                        {
                            //UIApplication.SharedApplication.CancelAllLocalNotifications();
                            //CrossLocalNotifications.Current.Cancel(10001000);
                            try
                            {
                                CrossLocalNotifications.Current.Show(alertTitle, alertContent, 10001000);
                            }
                            catch (Exception)
                            {
                            }
                        });
                    }
                }
            }
        }
예제 #19
0
        void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
        {
            // Check to see if the dictionary has the aps key.  This is the notification payload you would have sent
            if (null != options && options.ContainsKey(new NSString("aps")))
            {
                //Get the aps dictionary
                NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;

                string alert   = string.Empty;
                string id      = string.Empty;
                string message = string.Empty;
                string code    = string.Empty;
                string url     = string.Empty;

                if (aps.ContainsKey(new NSString("alert")))
                {
                    alert = (aps[new NSString("alert")] as NSString).ToString();
                }

                if (aps.ContainsKey(new NSString("id")))
                {
                    id = (aps[new NSString("id")] as NSString).ToString();
                }

                if (aps.ContainsKey(new NSString("message")))
                {
                    message = (aps[new NSString("message")] as NSString).ToString();
                }

                if (aps.ContainsKey(new NSString("code")))
                {
                    code = (aps[new NSString("code")] as NSString).ToString();
                }

                if (aps.ContainsKey(new NSString("Url")))
                {
                    url = (aps[new NSString("Url")] as NSString).ToString();
                }

                if (!fromFinishedLaunching && !string.IsNullOrEmpty(alert))
                {
                    UIAlertView avAlert = new UIAlertView(AppResources.ApplicationName, alert, null, "OK"); //TODO: Usar los recursos
                    avAlert.Clicked += (sender, buttonArgs) =>
                    {
                        App.Locator.LoaderPage.Start(id, message, code, url);
                    };

                    avAlert.Show();
                }
            }
        }
예제 #20
0
        public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
        {
            if (!change.ContainsKey("old".ToNSString()))
            {
                return;
            }

            if (!change.ContainsKey("new".ToNSString()))
            {
                return;
            }

            var oldRect = ((NSValue)change.ValueForKey("old".ToNSString())).CGRectValue;
            var newRect = ((NSValue)change.ValueForKey("new".ToNSString())).CGRectValue;

            if (oldRect.Size == newRect.Size)
            {
                return; // zoom/scroll event
            }
            var scrollView = ofObject as UIScrollView;

            if (scrollView == null)
            {
                return;
            }

            if (scrollView.Handle == IntPtr.Zero)
            {
                return;
            }

            UIView contentView;

            if (_contentView.TryGetTarget(out contentView))
            {
                if (contentView.Handle == IntPtr.Zero)
                {
                    SystemLog.Error("Content view was invalid");
                    return;
                }
                if (scrollView.Subviews.Length == 0)
                {
                    ConfigureScrollView(scrollView, contentView, ID);
                    //ClearContentViewReference();
                }
                else
                {
                    AdjustScrollView(scrollView, contentView, ID);
                }
            }
        }
예제 #21
0
        private static NSError OK_Error(this NSDictionary self)
        {
            if (self.ContainsKey(new NSString("error_code")))
            {
                return(new NSError(new NSString(OK_API_ERROR_CODE_DOMAIN), (self["error_code"] as NSNumber).NIntValue, NSDictionary.FromObjectAndKey(self["error_msg"], new NSString("NSLocalizedDescriptionKey"))));
            }

            if (self.ContainsKey(new NSString("error")))
            {
                return(new NSError(new NSString(OK_API_ERROR_CODE_DOMAIN), -1, NSDictionary.FromObjectAndKey(self["error"], new NSString("NSLocalizedDescriptionKey"))));
            }

            return(null);
        }
예제 #22
0
        public override void DidReceiveRemoteNotification(
            UIApplication application,
            NSDictionary userInfo,
            Action <UIBackgroundFetchResult> completionHandler)
        {
            NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;

            var messageKey       = new NSString("alert");
            var silentMessageKey = new NSString("content-available");
            var actionKey        = new NSString("action");

            string message = null;

            if (aps.ContainsKey(messageKey))
            {
                message = (aps[messageKey] as NSString).ToString();
            }

            // Show alert
            if (!string.IsNullOrEmpty(message))
            {
                UIApplication.SharedApplication.InvokeOnMainThread(() =>
                {
                    var alert = UIAlertController.Create(
                        "Notification",
                        message,
                        UIAlertControllerStyle.Alert);

                    alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));

                    var vc = UIApplication.SharedApplication.KeyWindow.RootViewController;
                    while (vc.PresentedViewController != null)
                    {
                        vc = vc.PresentedViewController;
                    }

                    vc.ShowDetailViewController(alert, vc);
                });
            }

            // If message template is silent message, parse action param
            if (aps.ContainsKey(silentMessageKey))
            {
                System.Diagnostics.Debug.WriteLine($"[PNS] Silent message received");
                var action = userInfo.ObjectForKey(new NSString("action")) as NSString;

                System.Diagnostics.Debug.WriteLine($"[PNS] Action required of type: {action}");
            }
        }
예제 #23
0
        public override void DidReceiveScriptMessage(WKUserContentController userContentController, WKScriptMessage message)
        {
            SystemLogger.Log(SystemLogger.Module.PLATFORM, "# IPhoneWKScriptMessageHandler - DidReceiveScriptMessage");

            try {
                NSDictionary body = message.Body as NSDictionary;

                string requestUrl = null;
                string query      = null;

                string serviceName = "undefined";
                string methodName  = "undefined";
                Object service     = null;

                if (body.ContainsKey(new NSString("uri")))
                {
                    requestUrl = (body ["uri"]).ToString();

                    // get service path
                    if (requestUrl != null)
                    {
                        if (requestUrl.StartsWith(IPhoneServiceLocator.APPVERSE_SERVICE_URI))
                        {
                            string commandParams = requestUrl.Substring(IPhoneServiceLocator.APPVERSE_SERVICE_URI.Length);
                            //SystemLogger.Log (SystemLogger.Module.PLATFORM, "# IPhoneWKScriptMessageHandler - commandParams: " + commandParams);
                            string[] commandParamsArray = commandParams.Split(new char[] { '/' });
                            serviceName = commandParamsArray [0];
                            methodName  = commandParamsArray [1];
                            //SystemLogger.Log (SystemLogger.Module.PLATFORM, "# IPhoneWKScriptMessageHandler - serviceName: " + serviceName);
                            //SystemLogger.Log (SystemLogger.Module.PLATFORM, "# IPhoneWKScriptMessageHandler - methodName: " + methodName);
                            service = serviceLocator.GetService(serviceName);
                        }
                    }
                }

                if (body.ContainsKey(new NSString("query")))
                {
                    query = (body ["query"]).ToString();
                    //SystemLogger.Log (SystemLogger.Module.PLATFORM, "# IPhoneWKScriptMessageHandler - query: " + query);
                }

                SystemLogger.Log(SystemLogger.Module.PLATFORM, "# IPhoneWKScriptMessageHandler - sending Async POST result for service: " + serviceName + ", and method: " + methodName);

                serviceURIHandler.ProcessAsyncPOSTResult(serviceInvocationManager, service, methodName, query);
            } catch (Exception ex) {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "# IPhoneWKScriptMessageHandler - exception handling WKScriptMessage. Exception message: " + ex.Message);
            }
        }
예제 #24
0
        void ProcessNotification(NSDictionary options, bool appIsActive)
        {
            // Check to see if the dictionary has the aps key.  This is the notification payload you would have sent
            if (null != options && options.ContainsKey(new NSString("aps")))
            {
                //Get the aps dictionary
                NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;

                string alert = string.Empty;

                //Extract the alert text
                // NOTE: If you're using the simple alert by just specifying
                // "  aps:{alert:"alert msg here"}  ", this will work fine.
                // But if you're using a complex alert with Localization keys, etc.,
                // your "alert" object from the aps dictionary will be another NSDictionary.
                // Basically the JSON gets dumped right into a NSDictionary,
                // so keep that in mind.
                if (aps.ContainsKey(new NSString("alert")))
                {
                    alert = (aps[new NSString("alert")] as NSString).ToString();
                }

                //If this came from the ReceivedRemoteNotification while the app was running,
                // we of course need to manually process things like the sound, badge, and alert.
                if (appIsActive)
                {
                    //Manually show an alert
                    if (!string.IsNullOrEmpty(alert))
                    {
                        UIAlertView avAlert = new UIAlertView("Notification", alert, null, AlertMessages.OkayTitle, null);
                        avAlert.Show();
                    }
                }
                else
                {
                    if (aps.ContainsKey(new NSString("jobid")))
                    {
                        string jobid = (aps[new NSString("jobid")] as NSString).ToString();
                        ((App)App.Current).OpenJobPage(jobid);
                    }
                    else if (aps.ContainsKey(new NSString("jobapplicantid")))
                    {
                        string jobapplicantid = (aps[new NSString("jobapplicantid")] as NSString).ToString();
                        ((App)App.Current).OpenJobApplicantPage(jobapplicantid);
                    }
                }
            }
        }
예제 #25
0
        void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
        {
            // Check to see if the dictionary has the aps key.  This is the notification payload you would have sent
            if (null != options && options.ContainsKey(new NSString("aps")))
            {
                //Get the aps dictionary
                NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;

                string alert = string.Empty;
                string title = string.Empty;
                string param = "Inicial";

                //Extract the alert text
                // NOTE: If you're using the simple alert by just specifying
                // "  aps:{alert:"alert msg here"}  ", this will work fine.
                // But if you're using a complex alert with Localization keys, etc.,
                // your "alert" object from the aps dictionary will be another NSDictionary.
                // Basically the JSON gets dumped right into a NSDictionary,
                // so keep that in mind.
                if (aps.ContainsKey(new NSString("alert")))
                {
                    alert = (aps[new NSString("alert")] as NSString).ToString();
                }

                if (aps.ContainsKey(new NSString("title")))
                {
                    title = (aps[new NSString("title")] as NSString).ToString();
                }

                if (aps.ContainsKey(new NSString("param")))
                {
                    Preferences.Set("pushParam", (aps[new NSString("param")] as NSString).ToString());
                    //param = (aps[new NSString("param")] as NSString).ToString();
                }

                //If this came from the ReceivedRemoteNotification while the app was running,
                // we of course need to manually process things like the sound, badge, and alert.
                if (!fromFinishedLaunching)
                {
                    //Manually show an alert
                    if (!string.IsNullOrEmpty(alert))
                    {
                        UIAlertView avAlert = new UIAlertView(title, alert, null, "OK", null);
                        avAlert.Show();
                    }
                }
            }
        }
        public NotificationModel ParceFromUNNotification(UNNotification notification)
        {
            NotificationModel notificationModel = new NotificationModel();

            if (notification.Request.Content.UserInfo.Keys.Count() != 0)
            {
                NSDictionary userInfo = notification.Request.Content.UserInfo;

                if (null != userInfo && userInfo.ContainsKey(new NSString("aps")))
                {
                    //Get the aps dictionary
                    NSDictionary aps   = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
                    NSDictionary alert = aps.ObjectForKey(new NSString("aps")) as NSDictionary;

                    notificationModel.AreaGUID        = (userInfo.ObjectForKey(new NSString("AreaGUID") as NSString))?.ToString();
                    notificationModel.NotificationUID = (userInfo.ObjectForKey(new NSString("NotificationUID") as NSString))?.ToString();
                    return(notificationModel);
                }

                if (userInfo.ContainsKey(new NSString("NotificationType")) && ((int.Parse((userInfo.ObjectForKey(new NSString("NotificationType") as NSString)).ToString())) == (int)NotificationType.LocalNotification))
                {
                    FeedActionModel actionModel = new FeedActionModel();

                    var action = userInfo.ObjectForKey(new NSString("Action")) as NSDictionary;

                    var actionParamDict = action.ObjectForKey(new NSString("ActionParamDict")) as NSDictionary;

                    actionModel.ActionScreen    = ((NSString)action["ActionScreen"]);
                    actionModel.ActionParamDict = new System.Collections.Generic.Dictionary <string, string>();
                    actionModel.WebRequestURL   = ((NSString)action["WebRequestUrl"]);

                    if (actionParamDict != null)
                    {
                        foreach (var item in actionParamDict)
                        {
                            actionModel.ActionParamDict.Add((NSString)item.Key, (NSString)item.Value);
                        }
                    }
                    notificationModel.Message          = notification.Request.Content.Body; // (alert[new NSString("NotificationUID")] as NSString)?.ToString();
                    notificationModel.NotificationType = NotificationType.LocalNotification;
                    notificationModel.Action           = actionModel;
                    notificationModel.AreaGUID         = (userInfo.ObjectForKey(new NSString("AreaGUID") as NSString))?.ToString();
                    //notificationModel = JsonConvert.DeserializeObject<NotificationModel>(userInfo.ToString());
                    return(notificationModel);
                }
            }
            return(notificationModel);
        }
예제 #27
0
        SketchStringAttribute ParseAttribute(NSDictionary attributeDict)
        {
            var fontDescriptorAttributes = attributeDict
                                           .GetAs <NSDictionary>("MSAttributedStringFontAttribute")
                                           .GetAs <NSDictionary>("NSFontDescriptorAttributes");

            var alignment = SketchTextAlignment.Left;

            if (attributeDict.ContainsKey("NSParagraphStyle"))
            {
                var paragraphStyle = attributeDict.GetAs <NSDictionary>("NSParagraphStyle");
                if (paragraphStyle.ContainsKey("NSAlignment"))
                {
                    alignment = ParseAlignment(paragraphStyle.GetAs <NSNumber>("NSAlignment"));
                }
            }

            // Looks like the color format of text objects in Sketch has changed between version 91 and 93
            // I've only found MSAttributedStringColorDictionaryAttribute in version 93. 2018-01-05 anette
            var sketchColor = SketchColor.Black;

            if (attributeDict.ContainsKey("NSColor"))
            {
                var nsDictionaryColor = attributeDict.GetAs <NSDictionary>("NSColor");
                sketchColor = ParseColor(nsDictionaryColor);
            }
            else if (attributeDict.ContainsKey("MSAttributedStringColorDictionaryAttribute"))
            {
                var components = attributeDict.GetAs <NSDictionary>("MSAttributedStringColorDictionaryAttribute");
                sketchColor = new SketchColor(
                    double.Parse(components["red"].ToString()),
                    double.Parse(components["green"].ToString()),
                    double.Parse(components["blue"].ToString()),
                    components.ContainsKey("alpha") ? double.Parse(components["alpha"].ToString()) : 1.0);
            }
            else
            {
                _log.Warning("Could not find color property for text object. Default to black.");
            }
            var fontSize = (double)fontDescriptorAttributes.GetAs <NSNumber>("NSFontSizeAttribute");

            return(new SketchStringAttribute
                   (
                       sketchColor,
                       fontSize,
                       alignment
                   ));
        }
예제 #28
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            viewController            = new MyViewController();
            window.RootViewController = viewController;

            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)
                    {
                        new UIAlertView(localNotification.AlertAction, localNotification.AlertBody, null, "OK", null).Show();
                        // reset our badge
                        UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
                    }
                }
            }

            return(true);
        }
예제 #29
0
		public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
		{
			// check for a notification
			if (launchOptions != null)
			{
				// check for a local notification
				if (launchOptions.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
				{
					var localNotification = launchOptions[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
					if (localNotification != null)
					{
						new UIAlertView(localNotification.AlertAction, localNotification.AlertBody, null, "OK", null).Show();
						// reset our badge
						UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
					}
				}
			}

			// iOS 7
			//UIApplication.SharedApplication.RegisterForRemoteNotificationTypes (UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge);

			// iOS 8
			var settings = UIUserNotificationSettings.GetSettingsForTypes(
				UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
				, null);
			UIApplication.SharedApplication.RegisterUserNotificationSettings (settings);
			UIApplication.SharedApplication.RegisterForRemoteNotifications ();

			return true;
		}
예제 #30
0
		public static void ProcessNotification (NSDictionary options, bool fromFinishedLaunching)
		{
			//Check to see if the dictionary has the aps key.  This is the notification payload you would have sent
			if (options.ContainsKey (new NSString (Resources.Communication.ApsRootElement))) {
				//Get the aps dictionary
				var aps = options.ObjectForKey (new NSString (Resources.Communication.ApsRootElement)) as NSDictionary;

				string alert = string.Empty;
				string sound = string.Empty;
				int badge = -1;

				//Extract the alert text
				//NOTE: If you're using the simple alert by just specifying "  aps:{alert:"alert msg here"}  "
				//      this will work fine.  But if you're using a complex alert with Localization keys, etc., your "alert" object from the aps dictionary
				//      will be another NSDictionary... Basically the json gets dumped right into a NSDictionary, so keep that in mind
				if (aps.ContainsKey (new NSString (Resources.Communication.ApsAlertElement))) {
					//alert = (aps [new NSString (Resources.Communication.ApsAlertElement)] as NSString).ToString ();
					alert = aps.ObjectForKey (new NSString (Resources.Communication.ApsAlertElement)).ToString ();
				}

				//Extract the sound string
				if (aps.ContainsKey (new NSString (Resources.Communication.ApsSoundElement))) {
					//sound = (aps [new NSString (Resources.Communication.ApsSoundElement)] as NSString).ToString ();
					sound = aps.ObjectForKey (new NSString (Resources.Communication.ApsSoundElement)).ToString ();
				}

				//Extract the badge
				if (aps.ContainsKey (new NSString (Resources.Communication.ApsBadgeElement))) {
					//string badgeStr = (aps [new NSString (Resources.Communication.ApsBadgeElement)] as NSString).ToString ();
					string badgeStr = aps.ObjectForKey (new NSString (Resources.Communication.ApsBadgeElement)).ToString ();
					int.TryParse (badgeStr, out badge);
				}

				//If this came from the ReceivedRemoteNotification while the app was running,
				// we of course need to manually process things like the sound, badge, and alert.
				if (!fromFinishedLaunching) {
					//Manually set the badge in case this came from a remote notification sent while the app was open
					if (badge >= 0)
						UIApplication.SharedApplication.ApplicationIconBadgeNumber = badge;
					/*
					//Manually play the sound
					if (!string.IsNullOrEmpty (sound)) {
						//This assumes that in your json payload you sent the sound filename (like sound.caf)
						// and that you've included it in your project directory as a Content Build type.
						var soundObj = MonoTouch.AudioToolbox.SystemSound.FromFile (sound);
						soundObj.PlaySystemSound ();
					}
					*/

					//Manually show an alert
					if (!string.IsNullOrEmpty (alert)) {
						using (UIAlertView avAlert = new UIAlertView ("Notification", alert, null, "OK", null)) {
							avAlert.Show ();
						}
					}
				}

			}
			
		}
예제 #31
0
        void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
        {
            // Check to see if the dictionary has the aps key.  This is the notification payload you would have sent
            if (null != options && options.ContainsKey(new NSString("aps")))
            {
                //Get the aps dictionary
                NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;

                string alert = string.Empty;

                if (aps.ContainsKey(new NSString("alert")))
                {
                    alert = (aps[new NSString("alert")] as NSString).ToString();
                }

                if (!fromFinishedLaunching)
                {
                    //Manually show an alert
                    if (!string.IsNullOrEmpty(alert))
                    {
                        UIAlertView avAlert = new UIAlertView("Notification", alert, null, "OK", null);
                        avAlert.Show();
                    }
                }
            }
        }
        public void OnMessageReceived(NSDictionary userInfo)
        {
            var parameters = new Dictionary<string, object>();
            var json = DictionaryToJson(userInfo);
            JObject values = JObject.Parse(json);

            var keyAps = new NSString("aps");

            if (userInfo.ContainsKey(keyAps))
            {
                NSDictionary aps = userInfo.ValueForKey(keyAps) as NSDictionary;

                if (aps != null)
                {
                    foreach (var apsKey in aps)
                    {
                        parameters.Add(apsKey.Key.ToString(), apsKey.Value);
                        JToken temp;
                        if (!values.TryGetValue(apsKey.Key.ToString(), out temp))
                            values.Add(apsKey.Key.ToString(), apsKey.Value.ToString());
                    }
                }
            }

            CrossPushNotification.PushNotificationListener.OnMessage(values, DeviceType.iOS);
        }
예제 #33
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)
		{
			window = new UIWindow (UIScreen.MainScreen.Bounds);
			
			viewController = new PushwooshSampleViewController ();
			window.RootViewController = viewController;
			window.MakeKeyAndVisible ();

			PushNotificationManager pushmanager = PushNotificationManager.PushManager;
			pushmanager.Delegate = this;

			if (options != null) {
				if (options.ContainsKey (UIApplication.LaunchOptionsRemoteNotificationKey)) { 
					pushmanager.HandlePushReceived (options);
				}
			}
			 
			pushmanager.RegisterForPushNotifications ();

			pushmanager.StartLocationTracking ();

			Console.WriteLine("HWID: " + pushmanager.GetHWID);

			return true;
		}
예제 #34
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)
		{
			window = new UIWindow (UIScreen.MainScreen.Bounds);
			
			viewController = new CW_IOS_SingleViewApplicationViewController ();
			window.RootViewController = viewController;
			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)
					{
						new UIAlertView(localNotification.AlertAction, localNotification.AlertBody, null, "OK", null).Show();
						// reset our badge
						UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
					}
				}
			}

			return true;
		}
예제 #35
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            //UserDialogs.Init();
            global::Xamarin.Forms.Forms.Init();
            Insights.Initialize("0d729b1f8027a9219421908d521e3af664ae52fc");
            PushNotificationManager pushmanager = PushNotificationManager.PushManager;
            pushmanager.Delegate = this;

            if (options != null)
            {
                if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
                { 
                    pushmanager.HandlePushReceived(options);
                }
            }

            pushmanager.RegisterForPushNotifications();

            try
            {
                var token = PushNotificationManager.PushManager.GetPushToken;
                
                if (!String.IsNullOrEmpty(token))
                    App.PushWooshToken = token;
            }
            catch (Exception ex)
            {
                Insights.Report(ex);
            }

            LoadApplication(new App());

            return base.FinishedLaunching(app, options);
        }
예제 #36
0
        void ProcessNotification(NSDictionary userInfo)
        {
            if (userInfo == null)
            {
                return;
            }

            Console.WriteLine("Received Notification");

            var apsKey = new NSString("aps");

            if (userInfo.ContainsKey(apsKey))
            {
                var alertKey = new NSString("alert");

                var aps = (NSDictionary)userInfo.ObjectForKey(apsKey);

                if (aps.ContainsKey(alertKey))
                {
                    var alert = (NSString)aps.ObjectForKey(alertKey);

                    try
                    {
                        var avAlert = new UIAlertView("TMTK Update", alert, null, "OK", null);
                        avAlert.Show();
                    }
                    catch (Exception ex)
                    {
                    }

                    Console.WriteLine("Notification: " + alert);
                }
            }
        }
예제 #37
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(
                    UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null
                );

                application.RegisterUserNotificationSettings(notificationSettings);
            }

            // check for a notification
            if (launchOptions != null)
            {
                // check for a local notification
                if (launchOptions.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
                {
                    var localNotification = launchOptions[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;
                    }
                }
            }
            return true;
        }
예제 #38
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // check for a notification
            if (launchOptions != null)
            {
                // check for a local notification
                if (launchOptions.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
                {
                    var localNotification = launchOptions[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
                    if (localNotification != null)
                    {
                        new UIAlertView(localNotification.AlertAction, localNotification.AlertBody, null, "OK", null).Show();
                        // reset our badge
                        UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
                    }
                }
            }

            // iOS 7
            //UIApplication.SharedApplication.RegisterForRemoteNotificationTypes (UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge);

            // iOS 8
            var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null);

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

            return(true);
        }
예제 #39
0
파일: AppDelegate.cs 프로젝트: bpug/LbkIos
		//
		// 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)
		{
#if DEBUG
#else
			//TestFlight.TakeOff ("ac104b5ca4df6cdfc5b9c63eb448f2af_NjMyMDYyMDEyLTAyLTE2IDExOjE5OjQ4LjkxMjI3Mw");
#endif	
			
#region Notification
			// check for a notification
			if (options != null) {
				/*
				// check for a local notification
				if (options.ContainsKey (UIApplication.LaunchOptionsLocalNotificationKey)) {
					
					UILocalNotification localNotification = options [UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
					if (localNotification != null) {
						
						new UIAlertView (localNotification.AlertAction, localNotification.AlertBody, null, "OK", null).Show ();
						// reset our badge
						UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
					}
				}
				*/
				// check for a remote notification
				if (options.ContainsKey (UIApplication.LaunchOptionsRemoteNotificationKey)) {
					
					NSDictionary remoteNotification = options [UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
					if (remoteNotification != null) {
						//new UIAlertView(""Notification, remoteNotification["alert"], null, "OK", null).Show();
						//PushNotifications.ProcessNotification (options, true);
						UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
					}
				}
			}
			
			//PushNotifications.Subscribe ();
#endregion			
			
			this.window = new UIWindow (UIScreen.MainScreen.Bounds);
			
			//---- instantiate a new home screen 
			RootViewController rootController = new RootViewController ();
			
			//---- instantiate a new navigation controller 
			this.rootNavigationController = new BaseNavigationController (rootController);
    
			//---- add the home screen to the navigation controller 
			// (it'll be the top most screen) 
			//this.rootNavigationController.PushViewController (rootController, false); 
    
			//---- set the root view controller on the window. the nav 
			// controller will handle the rest 
			this.window.RootViewController = this.rootNavigationController;
			this.window.MakeKeyAndVisible ();
			//showSplash (rootController);
			showSplashScreen ();
			return true;
			
		}
예제 #40
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary options)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method
            if (IoC.Dbconnect == null)
            {
                IoC.Dbconnect = new DatabaseConnection();
                InitSyncTables();
            }
            if (IoC.EventFactory == null)
            {
                IoC.EventFactory = new EventFactory();
            }
            if (IoC.ViewRefresher == null)
            {
                IoC.ViewRefresher = new ViewRefresher();
            }
            if (IoC.EmployeeFactory == null)
            {
                IoC.EmployeeFactory = new EmployeeFactory();
            }
            if (IoC.RecipientListFactory == null)
            {
                IoC.RecipientListFactory = new RecipientListFactory();
            }
            if (IoC.UserInfo == null)
            {
                IoC.UserInfo = new UserInfo();
            }
            SQLitePCL.CurrentPlatform.Init();

            var settings = UIUserNotificationSettings.GetSettingsForTypes(
              UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null);
            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);

            if (options != null)
            {
                // check for a 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));
                        ParentController.getNavigationMenu().ViewControllers[0].PresentViewController(okayAlertController, true, null);

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




            return true;
        }
예제 #41
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // create our window
            window = new UIWindow (UIScreen.MainScreen.Bounds);
            window.MakeKeyAndVisible ();

            home = new Screens.iPhone.Home.Home_iPhone ();
            home.View.Frame = new System.Drawing.RectangleF (0, UIApplication.SharedApplication.StatusBarFrame.Height, UIScreen.MainScreen.ApplicationFrame.Width, UIScreen.MainScreen.ApplicationFrame.Height);
            window.RootViewController = home;

            // check for a notification
            if (options != null) {

                // check for a local notification
                if (options.ContainsKey (UIApplication.LaunchOptionsLocalNotificationKey)) {

                    UILocalNotification localNotification = options [UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
                    if (localNotification != null) {

                        new UIAlertView (localNotification.AlertAction, localNotification.AlertBody, null, "OK", null).Show ();
                        // reset our badge
                        UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
                    }
                }

                // check for a remote notification
                if (options.ContainsKey (UIApplication.LaunchOptionsRemoteNotificationKey)) {

                    NSDictionary remoteNotification = options [UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
                    if (remoteNotification != null) {
                        //new UIAlertView(remoteNotification.AlertAction, remoteNotification.AlertBody, null, "OK", null).Show();
                    }
                }
            }

            //==== register for remote notifications and get the device token
            // set what kind of notification types we want
            UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge;
            // register for remote notifications
            UIApplication.SharedApplication.RegisterForRemoteNotificationTypes (notificationTypes);

            //
            return true;
        }
        //
        // 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)
        {
            NotificarePushLib.Shared().Launch ();
            _pushLibDelegate = new MyPushLibDelegate ();
            NotificarePushLib.Shared ().Delegate = _pushLibDelegate;

            if (options != null && options.ContainsKey( UIApplication.LaunchOptionsRemoteNotificationKey ) )
            {
                NotificarePushLib.Shared().HandleOptions (options [UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary);
            }

            return true;
        }
예제 #43
0
        /// <summary>
        /// Finished the launching.
        /// </summary>
        /// <param name="app">The app.</param>
        /// <param name="options">The options.</param>
        /// <returns>True or false.</returns>
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
			var iRate = MTiRate.iRate.SharedInstance;
			iRate.AppStoreID = 707173885;

			this.window = new UIWindow(UIScreen.MainScreen.Bounds);
            var presenter = new TouchViewPresenter(this.window);
            var setup = new Setup(this, presenter);
            setup.Initialize();

            Mvx.Resolve<CodeFramework.Core.Services.IErrorService>().Init("http://sentry.dillonbuchanan.com/api/5/store/", "17e8a650e8cc44678d1bf40c9d86529b ", "9498e93bcdd046d8bb85d4755ca9d330");

            // Setup theme
            Theme.Setup();

            if (options != null)
            {
                if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey)) 
                {
                    var remoteNotification = options[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
                    if(remoteNotification != null) {
                        HandleNotification(remoteNotification, true);
                    }
                }
            }

            var startup = Mvx.Resolve<IMvxAppStart>();
			startup.Start();

            this.window.MakeKeyAndVisible();

            InAppPurchases.Instance.PurchaseError += HandlePurchaseError;
            InAppPurchases.Instance.PurchaseSuccess += HandlePurchaseSuccess;

            var features = Mvx.Resolve<IFeaturesService>();

            // Automatic activations in debug mode!
            #if DEBUG
            Mvx.Resolve<CodeFramework.Core.Services.IDefaultValueService>().Set(FeatureIds.PushNotifications, true);
            #endif


			// Notifications don't work on teh simulator so don't bother
            if (MonoTouch.ObjCRuntime.Runtime.Arch != MonoTouch.ObjCRuntime.Arch.SIMULATOR && features.IsPushNotificationsActivated)
			{
				const UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge;
				UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
			}

            return true;
        }
        public override bool FinishedLaunching(UIApplication application, NSDictionary options)
        {
            if(options != null) {
                if(options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey)) {
                    // was woken from Local notification
                    var localNotification =
                        options[UIApplication.LaunchOptionsLocalNotificationKey] as
                            UILocalNotification;

                    if(localNotification != null) 
                        ReceivedLocalNotification(localNotification);
                }
                else if(options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey)) {
                    var remoteNotification =
                        options[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;

                    if(remoteNotification != null)
                        ReceivedRemoteNotification(remoteNotification);
                }
            }

            return true;
        }
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            PushNotificationManager pushmanager = PushNotificationManager.PushManager;
            pushmanager.Delegate = this;

            if (options != null) {

                if (options.ContainsKey (UIApplication.LaunchOptionsRemoteNotificationKey)) {

                    var data = (NSDictionary)options.ValueForKey (UIApplication.LaunchOptionsRemoteNotificationKey);

                    HandleRemoteNotification (data, true);
                }
            }
            return true;
        }
예제 #46
0
        /// <summary>
        /// Finished the launching.
        /// </summary>
        /// <param name="app">The app.</param>
        /// <param name="options">The options.</param>
        /// <returns>True or false.</returns>
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
			var iRate = MTiRate.iRate.SharedInstance;
			iRate.AppStoreID = 707173885;

			this.window = new UIWindow(UIScreen.MainScreen.Bounds);

            // Setup theme
            Theme.Setup();

            var presenter = new TouchViewPresenter(this.window);

            var setup = new Setup(this, presenter);
            setup.Initialize();

			Mvx.Resolve<CodeFramework.Core.Services.IAnalyticsService>().Init("UA-44040302-1", "CodeHub");

            if (options != null)
            {
                if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey)) 
                {
                    var remoteNotification = options[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
                    if(remoteNotification != null) {
                        HandleNotification(remoteNotification, true);
                    }
                }
            }

            var startup = Mvx.Resolve<IMvxAppStart>();
			startup.Start();

            this.window.MakeKeyAndVisible();

            InAppPurchases.Instance.PurchaseError += HandlePurchaseError;
            InAppPurchases.Instance.PurchaseSuccess += HandlePurchaseSuccess;

            var features = Mvx.Resolve<IFeaturesService>();

			// Notifications don't work on teh simulator so don't bother
            if (MonoTouch.ObjCRuntime.Runtime.Arch != MonoTouch.ObjCRuntime.Arch.SIMULATOR && features.IsPushNotificationsActivated)
			{
				const UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge;
				UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
			}

            return true;
        }
예제 #47
0
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			PushNotificationManager pushmanager = PushNotificationManager.PushManager;
			pushmanager.Delegate = this;
			UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge;
			UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);

			if (options != null) {
				if (options.ContainsKey (UIApplication.LaunchOptionsRemoteNotificationKey)) { 
					pushmanager.HandlePushReceived (options);
				}
			}

			pushmanager.StartLocationTracking ();

			return true;
		}
예제 #48
0
 public void PictureTaken(NSDictionary info)
 {
     if (info != null && info.ContainsKey(UIImagePickerController.OriginalImage))
       {
     UIImage image = info[UIImagePickerController.OriginalImage] as UIImage;
     if (image != null)
     {
       // Save it
       image.SaveToPhotosAlbum(null);
       // Show the image too... (replaces instructions)
       imageViewer.Image = image;
       imageViewer.Hidden = false;
       // Also change the button to hint the user can have another go
       takePictureButton.SetTitle("Again?", UIControlState.Normal);
     }
       }
 }
        async public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
        {
            if (null != userInfo && userInfo.ContainsKey(new NSString("aps")))
            {
                NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;

                string alert = string.Empty;
                if (aps.ContainsKey(new NSString("alert")))
                {
                    var nsString = aps[new NSString("alert")] as NSString;
                    if (nsString != null)
                        alert = nsString.ToString();
                }

                if (!string.IsNullOrEmpty(alert))
                {
                    //Show a pop-up if the application is open
                    UIAlertView avAlert = new UIAlertView("CRM Item", alert, null, "OK", null);
                    avAlert.Show();

                    BandClient client = MainViewController.GetClient();

                    //Connect to Band if not already connected
                    if (client == null)
                    {
                        try
                        {
                            BandClientManager manager = MainViewController.GetManager();
                            client = manager.AttachedClients.FirstOrDefault();
                            if (client == null) return;

                            client = MainViewController.GetClient();
                        }
                        catch (BandException) { }
                    }

                    if (client == null) return;

                    //Send to Band
                    await client.NotificationManager.SendMessageTaskAsync(MainViewController.GetTileId(), "CRM Item",
                        alert, DateTime.Now, true);
                }
            }
        }
예제 #50
0
        public void InitLocalNotifications(NSDictionary options)
        {
            var settings = UIUserNotificationSettings.GetSettingsForTypes(
                UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null);
            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);

            UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;

            if (options != null)
            {
                // check for a local notification
                if (options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
                {
                    var localNotification = options[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
                    if (localNotification != null)
                        new UIAlertView(localNotification.AlertAction, localNotification.AlertBody, null, "OK", null).Show();
                }
            }
        }
예제 #51
0
        public async override void HandleWatchKitExtensionRequest(UIApplication application, NSDictionary userInfo, Action<NSDictionary> reply)
        {
            if (userInfo.ContainsKey(new NSString("2015DailyAvg")))
            {
                //Kick off Background Task.
                var taskId = UIApplication.SharedApplication.BeginBackgroundTask(() =>
                    {
                    });

                var results = await CityOfBrandonApi.GetAll2015();
                var dictionary = new NSMutableDictionary();
                foreach (var d in results.OrderByDescending(x=>x.SamplingDate))
                    dictionary.Add(d.SamplingDate.DateTimeToNSDate(), new NSString(d.DailyAvgCount.ToString()));
                reply(dictionary);

                //End Background task
                UIApplication.SharedApplication.EndBackgroundTask(taskId);
            }

        }
예제 #52
0
        void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
        {
            if (null != options && options.ContainsKey(new NSString("aps")))
            {
                NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;

                string alert = string.Empty;

                if (aps.ContainsKey(new NSString("alert")))
                    alert = (aps[new NSString("alert")] as NSString).ToString();

                if (!fromFinishedLaunching)
                {
                    if (!string.IsNullOrEmpty(alert))
                    {
                        UIAlertView avAlert = new UIAlertView("Notification", alert, null, "OK", null);
                        avAlert.Show();
                    }
                }           
            }
        }
예제 #53
0
        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
        {
            if (application.ApplicationState == UIApplicationState.Active)
            {
                // Application in Foregroud, popup message
                if (userInfo.ContainsKey(NSObject.FromObject("aps")))
                {
                    var aps = userInfo["aps"] as NSMutableDictionary;
                    if (aps != null)
                    {
                        if (aps.ContainsKey(NSObject.FromObject("alert")))
                        {
                            var alert = (aps["alert"] ?? NSObject.FromObject("")).ToString();
                            new UIAlertView("Artportalen", alert, null, "Ok", null).Show();
                        }
                    }
                }
            }

            ParsePush.HandlePush(userInfo);
            completionHandler(UIBackgroundFetchResult.NoData);
        }
예제 #54
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary options)
        {
            //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(UIRemoteNotificationType.Alert
                                                                               | UIRemoteNotificationType.Badge
                                                                               | UIRemoteNotificationType.Sound);

            // check for a notification
            if(options != null) {

                // check for a local notification
            //				if(options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey)) {
            //
            //					UILocalNotification localNotification = options[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
            //					if(localNotification != null) {
            //
            //						new UIAlertView(localNotification.AlertAction, localNotification.AlertBody, null, "OK", null).Show();
            //						// reset our badge
            //						UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
            //					}
            //				}

                // check for a remote notification
                if(options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey)) {

                    NSDictionary remoteNotification = options[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
                    if(remoteNotification != null) {
            //						new UIAlertView(remoteNotification["AlertAction"].va, remoteNotification["AlertBody"], null, "OK", null).Show();
                    }
                }
            }

            Window.MakeKeyAndVisible ();

            return true;
        }
예제 #55
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)
		{
			window = new UIWindow (UIScreen.MainScreen.Bounds);
			
			viewController = new PushwooshSampleViewController ();
			window.RootViewController = viewController;
			window.MakeKeyAndVisible ();

			PushNotificationManager pushmanager = PushNotificationManager.PushManager;
			pushmanager.Delegate = this;
			UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge;
			UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);

			if (options != null) {
				if (options.ContainsKey (UIApplication.LaunchOptionsRemoteNotificationKey)) { 
					pushmanager.HandlePushReceived (options);
				}
			}

			pushmanager.StartLocationTracking ();

			return true;
		}
예제 #56
0
		void ProcessNotification (NSDictionary options, bool fromFinishedLaunching)
		{
			// Check to see if the dictionary has the aps key.  This is the notification payload you would have sent
			if (null != options && options.ContainsKey (new NSString ("aps"))) {
				//Get the aps dictionary
				NSDictionary aps = options.ObjectForKey (new NSString ("aps")) as NSDictionary;

				string command = string.Empty;

				//Extract the alert text
				// NOTE: If you're using the simple alert by just specifying
				// "  aps:{alert:"alert msg here"}  ", this will work fine.
				// But if you're using a complex alert with Localization keys, etc.,
				// your "alert" object from the aps dictionary will be another NSDictionary.
				// Basically the JSON gets dumped right into a NSDictionary,
				// so keep that in mind.
				if (aps.ContainsKey (new NSString ("command"))) {
					command = (aps [new NSString ("command")] as NSString).ToString ();
				}
				//If this came from the ReceivedRemoteNotification while the app was running,
				// we of course need to manually process things like the sound, badge, and alert.
				if (!fromFinishedLaunching) {
					//Manually show an alert
					if (!string.IsNullOrEmpty (command)) {
						if (command == RemoteCommands.Alert) {
							UIAlertView avAlert = new UIAlertView ("Notification", "Alert", null, "OK", null);
							avAlert.Show ();
						} else if (command == RemoteCommands.RefreshConferences) {
							Messenger.Default.Send (new ConferenceAddedMessage ());
						} else if (command == RemoteCommands.RefreshSchedule) {
							Messenger.Default.Send (new ConferenceAddedToScheduleMessage ());
						} 
					}
				}
			}
		}
예제 #57
0
        //public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
        //{
        //    ProcessNotification(userInfo, false);
        //}

        void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
        {
            // Check to see if the dictionary has the aps key.  This is the notification payload you would have sent
            if (null != options && options.ContainsKey(new NSString("aps")))
            {
                //Get the aps dictionary
                NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;

                string alert = string.Empty;

                //Extract the alert text
                // NOTE: If you're using the simple alert by just specifying 
                // "  aps:{alert:"alert msg here"}  " this will work fine.
                // But if you're using a complex alert with Localization keys, etc., 
                // your "alert" object from the aps dictionary will be another NSDictionary. 
                // Basically the json gets dumped right into a NSDictionary, 
                // so keep that in mind.
                if (aps.ContainsKey(new NSString("alert")))
                    alert = (aps[new NSString("alert")] as NSString).ToString();

                //If this came from the ReceivedRemoteNotification while the app was running,
                // we of course need to manually process things like the sound, badge, and alert.
                if (!fromFinishedLaunching)
                {
                    //Manually show an alert
                    if (!string.IsNullOrEmpty(alert))
                    {
                        if (this.NotificationRecieved != null)
                        this.NotificationRecieved(this, new AzureNotificationEventArgs(alert));
                        // UIAlertView avAlert = new UIAlertView("Notification", alert, null, "OK", null);
                        // avAlert.Show();
                    }
                }
            }
        }
예제 #58
0
        private void HandleNotification(NSDictionary data, bool fromBootup)
		{
			try
			{
				var viewDispatcher = Mvx.Resolve<Cirrious.MvvmCross.Views.IMvxViewDispatcher>();
                var appService = Mvx.Resolve<IApplicationService>();
                var repoId = new RepositoryIdentifier(data["r"].ToString());
                var parameters = new Dictionary<string, string>() {{"Username", repoId.Owner}, {"Repository", repoId.Name}};

                MvxViewModelRequest request;
                if (data.ContainsKey(new NSString("c")))
                {
                    request = MvxViewModelRequest<CodeHub.Core.ViewModels.ChangesetViewModel>.GetDefaultRequest();
                    parameters.Add("Node", data["c"].ToString());
                    parameters.Add("ShowRepository", "True");
                }
                else if (data.ContainsKey(new NSString("i")))
                {
                    request = MvxViewModelRequest<CodeHub.Core.ViewModels.Issues.IssueViewModel>.GetDefaultRequest();
                    parameters.Add("Id", data["i"].ToString());
                }
                else if (data.ContainsKey(new NSString("p")))
                {
                    request = MvxViewModelRequest<CodeHub.Core.ViewModels.PullRequests.PullRequestViewModel>.GetDefaultRequest();
                    parameters.Add("Id", data["p"].ToString());
                }
                else
                {
                    request = MvxViewModelRequest<CodeHub.Core.ViewModels.Repositories.RepositoryViewModel>.GetDefaultRequest();
                }

                request.ParameterValues = parameters;

                var username = data["u"].ToString();

                if (appService.Account == null || !appService.Account.Username.Equals(username))
                {
                    var user = appService.Accounts.FirstOrDefault(x => x.Username.Equals(username));
                    if (user != null)
                    {
                        appService.DeactivateUser();
                        appService.Accounts.SetDefault(user);
                    }
                }

                appService.SetUserActivationAction(() => viewDispatcher.ShowViewModel(request));

                if (appService.Account == null && !fromBootup)
                {
                    var startupViewModelRequest = MvxViewModelRequest<CodeHub.Core.ViewModels.App.StartupViewModel>.GetDefaultRequest();
                    viewDispatcher.ShowViewModel(startupViewModelRequest);
                }
			}
			catch (Exception e)
			{
				Console.WriteLine("Handle Notifications issue: " + e);
			}
		}
예제 #59
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            InitialTabTag = 4; //-1 was orginal

            StableSession.ApiGuid = "13e723d7763b494db92b13fc05c40214";
            StableSession.DeviceId = UIDevice.CurrentDevice.IdentifierForVendor.AsString();

            FBSettings.DefaultAppID = FacebookAppId;
            FBSettings.DefaultDisplayName = DisplayName;

#if DEBUG
            // Disable analytics when running in debug.
            GAI.SharedInstance.DryRun = true;
#endif
            GAI.SharedInstance.DispatchInterval = 20;
            GAI.SharedInstance.TrackUncaughtExceptions = true;
            GoogleTracker = GAI.SharedInstance.GetTracker(GoogleAnalyticsId);
            GoogleTracker.SetAllowIdfaCollection(true);

            Interfaces.Instance.HMAC256Interface = new HMACSHA256_iOS();
            Interfaces.Instance.FacebookInterface = new Facebook_iOS();
            Interfaces.Instance.NetworkTesterInterface = new NetworkTester_iOS();

            
            // Register for push notifications
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                const UIUserNotificationType notificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
                var settings = UIUserNotificationSettings.GetSettingsForTypes(notificationTypes, new NSSet());
                UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
            }
            else
            {
                const UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
            }

            if (options != null)
            {
                if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
                {
                    NSDictionary userInfo = options[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
                    if (userInfo != null)
                    {
                        NSDictionary aps = userInfo["aps"] as NSDictionary;
                        if (aps != null)
                        {
                            if (aps.ContainsKey(new NSString("mail_id")))
                            {
                                InitialTabTag = 1;
                            }
                            else if (aps.ContainsKey(new NSString("event_id")))
                            {
                                InitialTabTag = 2;
                            }
                        }
                    }
                }
            }

            MailHelper.Instance.UnreadCountChanged += MailHelperOnUnreadCountChanged;
            CalendarHelper.Instance.PendingEventsChanged += CalendarHelperOnPendingEventsChanged;

			// Här sätter vi central navigeringsfärg för hela appen till rosa färgen och vit text
			UINavigationBar.Appearance.BarTintColor = new UIColor (0.357f, 0.812f , 0.996f, 1.00f);//...
			//			UINavigationBar.Appearance.BarTintColor = UIColor.FromRGBA (20, 54, 109, 1);
			UINavigationBar.Appearance.TintColor = UIColor.White;
			UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes()
				{

					TextColor = UIColor.White
				});
			
            return true;
        }
예제 #60
0
		public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
		{
			Shared = this;

			if (App == null) {
				throw new ApplicationException ("You must set the App property before calling FinishedLaunching");
			}

			//
			// Initialize the caches
			//
			try {
				var docsDir = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
				var cachesDir = Path.GetFullPath (Path.Combine (docsDir, "../Library/Caches"));
				ThumbnailCache = new ImageCache (Path.Combine (cachesDir, "Thumbnails"));
			} catch (Exception ex) {
				Log.Error (ex);
			}

			//
			// Pay attention to the culture
			//
			try {
				UpdateCurrentCulture ();
				NSLocale.Notifications.ObserveCurrentLocaleDidChange ((s, e) => UpdateCurrentCulture ());
			} catch (Exception ex) {
				Log.Error (ex);
			}

			//
			// Learn about the device
			//
			try {
				DeviceFileSystemProvider.DeviceName = UIDevice.CurrentDevice.Name;
				//			if (!UIDevice.CurrentDevice.CheckSystemVersion (7, 0)) {
				//				app.SetStatusBarStyle (UIStatusBarStyle.BlackOpaque, false);
				//			}
			} catch (Exception ex) {
				Log.Error (ex);				
			}

			//
			// Load the settings
			//
			try {
				Settings = CreateSettings ();
				Settings.RunCount++;
				//			Console.WriteLine ("RUN COUNT = " + Settings.RunCount);
			} catch (Exception ex) {
				Log.Error (ex);				
			}


			//
			// Apply the theme
			//
			try {
				WhiteTheme.IsModern = ios7;

				UpdateTheme ();

			} catch (Exception ex) {
				Log.Error (ex);				
			}

			//
			// Initialize the file system manager
			//
			try {
				if (Settings.IsFirstRun () && !string.IsNullOrEmpty (App.AutoOpenDocumentPath))
					Settings.LastDocumentPath = App.AutoOpenDocumentPath;
				
				OpenedDocIndex = -1;
				FileSystemManager.Shared = new FileSystemManager ();
				FileSystemManager.Shared.ActiveFileSystem = new EmptyFileSystem {
					Description = "Loading Storage...",
				};
			} catch (Exception ex) {
				Log.Error (ex);				
			}

			//
			// Load the MRU
			//
			mru.InitializeMRU ();

			//
			// Patron
			//
			try {
				if (App.IsPatronSupported) {
					if (Settings.IsPatron) {
						Settings.IsPatron = DateTime.UtcNow < Settings.PatronEndDate;
					}
					StoreManager.Shared.CompletionActions.Add (PatronForm.HandlePurchaseCompletionAsync);
					StoreManager.Shared.FailActions.Add (PatronForm.HandlePurchaseFailAsync);
				}				
			} catch (Exception ex) {
				Log.Error (ex);
			}

			//
			// Start in app purchase data
			//
			try {
				StoreKit.SKPaymentQueue.DefaultQueue.AddTransactionObserver (StoreManager.Shared);
			} catch (Exception ex) {
				Log.Error (ex);				
			}

			//
			// Construct the UI
			//
			try {
				var docList = CreateDirectoryViewController ("");
				docListNav = CreateDocumentsNavigationController (docList);
				docListNav.NavigationBar.BarStyle = Theme.NavigationBarStyle;
				docListNav.ToolbarHidden = false;
				Theme.Apply (docListNav);
			} catch (Exception ex) {
				Log.Error (ex);				
			}

			window = new UIWindow (UIScreen.MainScreen.Bounds);

			try {
				SetRootViewController ();
				
				if (ios7) {
					window.TintColor = Praeclarum.Graphics.ColorEx.GetUIColor (App.TintColor);
				}
			} catch (Exception ex) {
				Log.Error (ex);				
			}

			window.MakeKeyAndVisible ();

			var shouldPerformAdditionalDelegateHandling = true;

			UIApplicationShortcutItem scitem = null;
			if (ios9) {
				var scitemKey = UIApplication.LaunchOptionsShortcutItemKey;
				if (launchOptions != null && launchOptions.ContainsKey (scitemKey)) {
					shouldPerformAdditionalDelegateHandling = false;
					scitem = launchOptions [scitemKey] as UIApplicationShortcutItem;
				}
			}

			//
			// Init the file system
			//
			try {
				var uiSync = TaskScheduler.FromCurrentSynchronizationContext ();
				initFileSystemTask = InitFileSystem ();
					
				initFileSystemTask.ContinueWith (async t => {
					if (!t.IsFaulted) {
						App.OnFileSystemInitialized ();
						try {
							CurrentDocumentListController.LoadDocs ().ContinueWith (tt => {
								if (tt.IsFaulted) {
									Log.Error (tt.Exception);
								}
							});
						} catch (Exception ex) {
							Log.Error (ex);
						}
						try {
							if (scitem != null) {
								await HandleShortcutItemAsync (scitem);
							}
						} catch (Exception ex) {
							Log.Error (ex);
						}
					} else {
						Debug.WriteLine (t.Exception);
					}
				}, uiSync);
			} catch (Exception ex) {
				Log.Error (ex);				
			}

			return shouldPerformAdditionalDelegateHandling;
		}