public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            // Get current device token
            var DeviceToken = deviceToken.Description;

            if (!string.IsNullOrWhiteSpace(DeviceToken))
            {
                DeviceToken = DeviceToken.Trim('<').Trim('>');
                DeviceToken = Regex.Replace(DeviceToken, @"\s+", "");
            }

            // Get previous device token
            var oldDeviceToken = NSUserDefaults.StandardUserDefaults.StringForKey("PushDeviceToken");

            // Has the token changed?
            if (string.IsNullOrEmpty(oldDeviceToken) || !oldDeviceToken.Equals(DeviceToken))
            {
                //TODO: Put your own logic here to notify your server that the device token has changed/been created!
                Console.WriteLine("RECIEVED TOKEN! " + DeviceToken);
                Settings.ApnsToken = DeviceToken;
                if (FireAuth.auth != null && !FireAuth.isTokenExpired() && FireDatabase.isDatabaseInit())
                {
                    FireDatabase.write("users/" + FireAuth.auth.User.LocalId + "/device_info/apns_token", DeviceToken);
                }
            }

            // Save new device token
            NSUserDefaults.StandardUserDefaults.SetString(DeviceToken, "PushDeviceToken");
        }
 public void StopLocationUpdates()
 {
     if (CLLocationManager.LocationServicesEnabled)
     {
         LocMgr.StopUpdatingLocation();
     }
     FireDatabase.write("cities/" + FireDatabase.currentCity + "/driver_locations/" + FireAuth.auth.User.LocalId, null);
 }
        public void locupdated(object sender, LocationUpdatedEventArgs e)
        {
            if (IOSRegisterDriverMode.shouldPushLocation)
            {
                Task.Factory.StartNew(() =>
                {
                    var userDB = FireDatabase.read("users/" + FireAuth.auth.User.LocalId).Result;
                    //Dictionary<string, Object> children = new Dictionary<string, Object>();
                    if (userDB.ContainsKey("stage_1_driving"))
                    {
                        string stageID = userDB["stage_1_driving"].ToString();
                        Dictionary <string, Object> tracker = new Dictionary <string, Object>();
                        tracker.Add("lat", e.Location.Coordinate.Latitude);
                        tracker.Add("lng", e.Location.Coordinate.Longitude);
                        tracker.Add("time", Time.CurrentTimeMillis());
                        FireDatabase.write("stage_1_ids/" + stageID + "/tracker/" + Time.CurrentTimeMillis(), tracker);
                    }

                    if (userDB.ContainsKey("is_driving"))
                    {
                        string rideID = userDB["is_driving"].ToString();
                        Dictionary <string, Object> tracker = new Dictionary <string, Object>();
                        tracker.Add("lat", e.Location.Coordinate.Latitude);
                        tracker.Add("lng", e.Location.Coordinate.Longitude);
                        tracker.Add("time", Time.CurrentTimeMillis());
                        FireDatabase.write("rides/" + rideID + "/tracker/" + Time.CurrentTimeMillis(), tracker);
                        FireDatabase.write("rides/" + rideID + "/latest_tracker", tracker);
                    }

                    Dictionary <string, Object> location = new Dictionary <string, Object>();
                    location.Add("lat", e.Location.Coordinate.Latitude);
                    location.Add("lng", e.Location.Coordinate.Longitude);
                    FireDatabase.write("cities/" + FireDatabase.currentCity + "/driver_locations/" + FireAuth.auth.User.LocalId, location);
                    if (!IOSRegisterDriverMode.shouldPushLocation)
                    {
                        FireDatabase.write("cities/" + FireDatabase.currentCity + "/driver_locations/" + FireAuth.auth.User.LocalId, null);
                    }
                    //FireDatabase.write("", children);
                });
            }
        }