Ejemplo n.º 1
0
        public bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            Window = new UIWindow(UIScreen.MainScreen.Bounds);
            if (Globals.Database.Table <CloudModel>().Count() > 0)
            {
                Window.RootViewController = UIStoryboard.FromName("Main", NSBundle.MainBundle).InstantiateViewController("MainScreen");
                if (PHPhotoLibrary.AuthorizationStatus == PHAuthorizationStatus.Authorized &&
                    Globals.Database.CheckSetting(UserSettings.AutoBackupPhotos, "1"))
                {
                    application.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum);
                }
            }
            else
            {
                Window.RootViewController = UIStoryboard.FromName("Main", NSBundle.MainBundle).InstantiateViewController("WelcomeScreen");
                application.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalNever);
            }
            Window.MakeKeyAndVisible();

            if (networkNotification == null)
            {
                networkNotification = CFNotificationCenter.Darwin.AddObserver(Notifications.NetworkChange, null, ObserveNetworkChange, CFNotificationSuspensionBehavior.Coalesce);
            }



            return(true);
        }
Ejemplo n.º 2
0
        public void TestObservers()
        {
            var target = new NSObject();
            var d      = CFNotificationCenter.Local;
            int count  = 0;
            int count2 = 0;
            CFNotificationObserverToken o2 = null;
            var o1 = d.AddObserver("hello", target, (x, dd) => {
                count++;
//				Console.WriteLine ("Here");

                if (count == 1)
                {
                    o2 = d.AddObserver("hello", target, (y, ee) => {
//						Console.WriteLine ("There");
                        count2++;
                    });
                }
            });

            d.PostNotification("hello", target, null, deliverImmediately: true);
            Assert.AreEqual(1, count);
            d.PostNotification("hello", target, null, deliverImmediately: true);
            Assert.AreEqual(2, count);
            Assert.AreEqual(1, count2);

            // Remove the first observer, count should not be updated
            d.RemoveObserver(o1);
            d.PostNotification("hello", target, null);
            Assert.AreEqual(2, count);
            Assert.AreEqual(2, count2);

            // Remove the last observer, there should be no change in count
            d.RemoveObserver(o2);
            d.PostNotification("hello", target, null);
            Assert.AreEqual(2, count);
            Assert.AreEqual(2, count2);

            // Test removing all observers
            count = 0;
            o1    = d.AddObserver("hello", target, (x, dd) => {
                count++;
                Console.WriteLine("Here");
            });
            o2 = d.AddObserver("hello", target, (y, ee) => { count++; });
            d.RemoveEveryObserver();
            d.PostNotification("hello", target, null);
            Assert.AreEqual(0, count);

            // Test removing from a callback
            count = 0;
            o2    = d.AddObserver("hello", target, (y, ee) => { count++; d.RemoveObserver(o2); });
            d.PostNotification("hello", target, null);
            Assert.AreEqual(1, count);
            d.PostNotification("hello", target, null);
            Assert.AreEqual(1, count);
        }
Ejemplo n.º 3
0
 public void WillEnterForeground(UIApplication application)
 {
     try
     {
         networkNotification = CFNotificationCenter.Darwin.AddObserver(Notifications.NetworkChange, null, ObserveNetworkChange, CFNotificationSuspensionBehavior.Coalesce);
         Globals.CloudManager?.StartNetwork(false);
     }
     catch
     {
         // Ignored.
     }
 }
Ejemplo n.º 4
0
        public void TestObservers2()
        {
            var d      = CFNotificationCenter.Local;
            int count  = 0;
            int count2 = 0;
            CFNotificationObserverToken o2 = null;
            var o1 = d.AddObserver(null, null, (x, dd) => {
                count++;
                if (count == 1)
                {
                    o2 = d.AddObserver(null, null, (y, ee) => {
                        count2++;
                    });
                }
            });

            d.PostNotification("hello", null, null, deliverImmediately: true);
            Assert.AreEqual(1, count);
            NSNotificationCenter.DefaultCenter.PostNotificationName("hello", null);
            Assert.AreEqual(2, count);
            Assert.AreEqual(1, count2);

            // Remove the first observer, count should not be updated
            d.RemoveObserver(o1);
            d.PostNotification("hello", null, null);
            Assert.AreEqual(2, count);
            Assert.AreEqual(2, count2);

            // Remove the last observer, there should be no change in count
            d.RemoveObserver(o2);
            NSNotificationCenter.DefaultCenter.PostNotificationName("hello", null);
            Assert.AreEqual(2, count);
            Assert.AreEqual(2, count2);

            // Test removing all observers
            count = 0;
            o1    = d.AddObserver(null, null, (x, dd) => {
                count++;
            });
            o2 = d.AddObserver(null, null, (y, ee) => { count++; });
            d.RemoveEveryObserver();
            NSNotificationCenter.DefaultCenter.PostNotificationName("hello", null);
            Assert.AreEqual(0, count);

            // Test removing from a callback
            count = 0;
            o2    = d.AddObserver(null, null, (y, ee) => { count++; d.RemoveObserver(o2); });
            d.PostNotification("hello", null, null);
            Assert.AreEqual(1, count);
            NSNotificationCenter.DefaultCenter.PostNotificationName("hello", null);
            Assert.AreEqual(1, count);
        }
Ejemplo n.º 5
0
 public void DidEnterBackground(UIApplication application)
 {
     try
     {
         if (networkNotification != null)
         {
             CFNotificationCenter.Darwin.RemoveObserver(networkNotification);
             networkNotification = null;
         }
     }
     catch
     {
         // Ignored.
     }
 }