Example #1
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            //init NavigationController
            var myMoodViewController = new MyMoodViewController();

            this.navController = new UINavigationController(myMoodViewController);
            this.navController.SetNavigationBarHidden(true, false);

            if (app.RespondsToSelector(new Selector("setStatusBarHidden: withAnimation:")))
            {
                app.SetStatusBarHidden(true, UIStatusBarAnimation.Fade);
            }
            else
            {
                app.SetStatusBarHidden(true, true);
            }

            //init db
            string version = NSBundle.MainBundle.ObjectForInfoDictionary("Version").ToString();

            db = new MyMoodViciDbContext(version, null);

            NSNotificationCenter.DefaultCenter.AddObserver(this, new Selector("SyncDataAndNotifications"), "SyncDataAndNotifications", null);

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

            CheckForGoLive();

            this.ShowBadgeNumber();

            startBackgroundThread();
            var appState = ApplicationState.Current;

            if (version != appState.CurrentVersion && appState.ForceUpdate > 0)
            {
                UpdateRequiredViewController uc = new UpdateRequiredViewController();
                navController.PushViewController(uc, true);
            }
            else
            {
                if (options != null)
                {
                    NSString pId = new NSString("PromptId");
                    //Console.WriteLine("Launching with options - {0}", options);
                    var startupLocalNotification  = options.ValueForKey(UIApplication.LaunchOptionsLocalNotificationKey) as UILocalNotification;
                    var startupRemoteNotification = options.ValueForKey(UIApplication.LaunchOptionsRemoteNotificationKey);
                    if (startupLocalNotification != null && startupLocalNotification.UserInfo != null)
                    {
                        //Console.WriteLine("Local notification prompt recieved as option");
                        NSString promptId = (NSString)startupLocalNotification.UserInfo.ValueForKey(pId);
                        myMoodViewController.promptID = promptId.ToString();
                    }
                    else
                    {
                        //Console.WriteLine("Remote notification recieved as option");
                        myMoodViewController.EnteredViaRemoteNotification = true;
                    }
                }
            }
            window.RootViewController = this.navController;
            // make the window visible
            window.MakeKeyAndVisible();

            //Register for remote notifications
            UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(UIRemoteNotificationType.Alert
                                                                               | UIRemoteNotificationType.Badge
                                                                               | UIRemoteNotificationType.Sound);

            return(true);
        }