static Task <IEnumerable <string> > GetAddressesForPositionAsync(Position position) { var location = new CLLocation(position.Latitude, position.Longitude); var geocoder = new CCLGeocoder(); var source = new TaskCompletionSource <IEnumerable <string> >(); geocoder.ReverseGeocodeLocation(location, (placemarks, error) => { if (placemarks == null) { placemarks = new CLPlacemark[0]; } List <string> addresses = new List <string>(); #if __MOBILE__ addresses = placemarks.Select(p => ABAddressFormatting.ToString(p.AddressDictionary, false)).ToList(); #else foreach (var item in placemarks) { var address = new CNMutablePostalAddress(); address.Street = item.AddressDictionary["Street"] == null ? "" : item.AddressDictionary["Street"].ToString(); address.State = item.AddressDictionary["State"] == null ? "" : item.AddressDictionary["State"].ToString(); address.City = item.AddressDictionary["City"] == null ? "" : item.AddressDictionary["City"].ToString(); address.Country = item.AddressDictionary["Country"] == null ? "" : item.AddressDictionary["Country"].ToString(); address.PostalCode = item.AddressDictionary["ZIP"] == null ? "" : item.AddressDictionary["ZIP"].ToString(); addresses.Add(CNPostalAddressFormatter.GetStringFrom(address, CNPostalAddressFormatterStyle.MailingAddress)); } #endif source.SetResult(addresses); }); return(source.Task); }
static Task <IEnumerable <string> > GetAddressesForPositionAsync(Position position) { var location = new CLLocation(position.Latitude, position.Longitude); var geocoder = new CCLGeocoder(); var source = new TaskCompletionSource <IEnumerable <string> >(); geocoder.ReverseGeocodeLocation(location, (placemarks, error) => { if (placemarks == null) { placemarks = new CLPlacemark[0]; } List <string> addresses = new List <string>(); #if __MOBILE__ && !(MACCATALYST || MACOS || __MACCATALYST__) #pragma warning disable BI1234, CA1416 // Type or member is obsolete, ABAddressFormatting.ToString(...) has [UnsupportedOSPlatform("ios9.0")] addresses = placemarks.Select(p => ABAddressFormatting.ToString(p.AddressDictionary, false)).ToList(); #pragma warning restore BI1234, CA1416 // Type or member is obsolete #else foreach (var item in placemarks) { var address = new CNMutablePostalAddress(); #pragma warning disable CA1416 // TODO: 'CLPlacemark.AddressDictionary' is unsupported on: 'maccatalyst' 11.0 and later address.Street = item.AddressDictionary["Street"] == null ? "" : item.AddressDictionary["Street"].ToString(); address.State = item.AddressDictionary["State"] == null ? "" : item.AddressDictionary["State"].ToString(); address.City = item.AddressDictionary["City"] == null ? "" : item.AddressDictionary["City"].ToString(); address.Country = item.AddressDictionary["Country"] == null ? "" : item.AddressDictionary["Country"].ToString(); address.PostalCode = item.AddressDictionary["ZIP"] == null ? "" : item.AddressDictionary["ZIP"].ToString(); #pragma warning restore CA1416 addresses.Add(CNPostalAddressFormatter.GetStringFrom(address, CNPostalAddressFormatterStyle.MailingAddress)); } #endif source.SetResult(addresses); }); return(source.Task); }
void MapView_RegionChanged(object sender, MKMapViewChangeEventArgs e) { var mapView = (MKMapView)sender; _geocoder.ReverseGeocodeLocation(new CLLocation(mapView.CenterCoordinate.Latitude, mapView.CenterCoordinate.Longitude), (placemarks, error) => { if (placemarks.Any()) { var address = ABAddressFormatting.ToString(placemarks[0].AddressDictionary, addCountryName: false); _addressChanged.Invoke(address); } }); }
public void ChateauFrontenac() { using (NSMutableDictionary dict = new NSMutableDictionary() { { new NSString("Street"), new NSString("1–3 Rue Des Carrières") }, { new NSString("SubAdministrativeArea"), new NSString("Québec") }, { new NSString("Thoroughfare"), new NSString("Rue Des Carrières") }, { new NSString("ZIP"), new NSString("G1R 5J5") }, { new NSString("Name"), new NSString("1–3 Rue Des Carrières") }, { new NSString("City"), new NSString("Quebec City") }, { new NSString("State"), new NSString("Quebec") }, { new NSString("SubLocality"), new NSString("Vieux-Quebec") }, { new NSString("SubThoroughfare"), new NSString("1-3") }, { new NSString("CountryCode"), new NSString("CA") }, }) { string expected1 = "1–3 Rue Des Carrières\nQuebec City Quebec G1R 5J5"; string expected2 = "1–3 Rue Des Carrières\nQuebec City Quebec G1R 5J5"; // there's a "(char) 8206" character just after 'Quebec' string expected; string s = ABAddressFormatting.ToString(dict, false); if (TestRuntime.CheckXcodeVersion(9, 0)) { expected = expected2; } else { expected = expected1; } Assert.That(s, Is.EqualTo(expected), "false"); // country names can be translated, e.g. chinese, so we can't compare it s = ABAddressFormatting.ToString(dict, true); Assert.That(s, Does.StartWith(expected), "prefix"); // Apple broke this again (8.0.x are hard to predict) - test will fail once it's corrected // iOS 8.1.2 device: working // iOS 8.0 (12A365) simulator (Xcode 6.0.1): working // iOS 8.1 (12B411) simulator (Xcode 6.1): broken // iOS 8.2 beta 5 (12D5480a) simulator (Xcode 6.2 beta 5): working // we don't check before 8.2 - where both device and simulators works again properly if (!TestRuntime.CheckSystemVersion(PlatformName.iOS, 8, 2)) { return; } // iOS 11.0 beta 1, 2, 3 and 4 are broken // and I give up (this test was not meant to track Apple breakages) } }
static Task <IEnumerable <string> > GetAddressesForPositionAsync(Position position) { var location = new CLLocation(position.Latitude, position.Longitude); var geocoder = new CLGeocoder(); var source = new TaskCompletionSource <IEnumerable <string> >(); geocoder.ReverseGeocodeLocation(location, (placemarks, error) => { if (placemarks == null) { placemarks = new CLPlacemark[0]; } IEnumerable <string> addresses = placemarks.Select(p => ABAddressFormatting.ToString(p.AddressDictionary, false)); source.SetResult(addresses); }); return(source.Task); }
public void ChateauFrontenac() { using (NSMutableDictionary dict = new NSMutableDictionary() { { new NSString("Street"), new NSString("1–3 Rue Des Carrières") }, { new NSString("SubAdministrativeArea"), new NSString("Québec") }, { new NSString("Thoroughfare"), new NSString("Rue Des Carrières") }, { new NSString("ZIP"), new NSString("G1R 5J5") }, { new NSString("Name"), new NSString("1–3 Rue Des Carrières") }, { new NSString("City"), new NSString("Quebec City") }, { new NSString("State"), new NSString("Quebec") }, { new NSString("SubLocality"), new NSString("Vieux-Quebec") }, { new NSString("SubThoroughfare"), new NSString("1-3") }, { new NSString("CountryCode"), new NSString("CA") }, }) { string expected = "1–3 Rue Des Carrières\nQuebec City Quebec G1R 5J5"; string s = ABAddressFormatting.ToString(dict, false); Assert.That(s, Is.EqualTo(expected), "false"); // country names can be translated, e.g. chinese, so we can't compare it s = ABAddressFormatting.ToString(dict, true); Assert.True(s.StartsWith(expected, StringComparison.Ordinal), "prefix"); // Apple broke this again (8.0.x are hard to predict) - test will fail once it's corrected // iOS 8.1.2 device: working // iOS 8.0 (12A365) simulator (Xcode 6.0.1): working // iOS 8.1 (12B411) simulator (Xcode 6.1): broken // iOS 8.2 beta 5 (12D5480a) simulator (Xcode 6.2 beta 5): working // we don't check before 8.2 - where both device and simulators works again properly if (!UIDevice.CurrentDevice.CheckSystemVersion(8, 2)) { return; } Assert.That(s [expected.Length], Is.EqualTo('\n'), "newline"); Assert.That(s.Length > expected.Length + 1, "country"); } }
private void OnGUI() { KitchenSink.OnGUIBack(); GUILayout.BeginArea(new Rect(50, 50, Screen.width - 100, Screen.height / 2 - 50)); //this is the original way of how objective C use call back functions: Delegates using separate files. //in this case the file is PeoplePickerNavigationControllerDelegate.cs //we have have it easier to use delegates instead of creating new files for each delegate. //see examples above. Ex: PersonalXT.CalendarAccess += delegate( .... if (GUILayout.Button("pick/select from contacts", GUILayout.ExpandHeight(true))) { ABPeoplePickerNavigationController picker = new ABPeoplePickerNavigationController(); if (pickerDelegate == null) { pickerDelegate = new PeoplePickerNavigationControllerDelegate(); } picker.peoplePickerDelegate = pickerDelegate; UIApplication.deviceRootViewController.PresentViewController(picker, true, null); } if (GUILayout.Button("get all contacts", GUILayout.ExpandHeight(true))) { Log("Address book authorization status: " + ABAddressBook.GetAuthorizationStatus()); var addressBook = ABAddressBook.Create(null, null); addressBook.RequestAccess(delegate(bool granted, NSError error) { Log("Granted: " + granted); //convienent function to get the names of the contacts string[] contactList = PersonalXT.GetAllContactNames(); for (int i = 0; i < contactList.Length; i++) { Log("Contact " + i + ": " + contactList[i]); } }); } if (GUILayout.Button("add new contacts", GUILayout.ExpandHeight(true))) { addNewContact(); } if (GUILayout.Button("init Calendar and show events within 30 days", GUILayout.ExpandHeight(true))) { checkEventStoreAccessForCalendar(); } if (GUILayout.Button("add an event for tomorrow", GUILayout.ExpandHeight(true))) { addEventForTomorrow(); } if (GUILayout.Button("add alarm to events", GUILayout.ExpandHeight(true))) { createAlarmForEvents(); } if (GUILayout.Button("add reminder with geolocation of current location", GUILayout.ExpandHeight(true))) { PersonalXT.RequestReminderAccess(); } if (GUILayout.Button("reverse geocode happiest place on earth", GUILayout.ExpandHeight(true))) { CLLocation location = new CLLocation(33.809, -117.919); CLGeocoder geocoder = new CLGeocoder(); geocoder.ReverseGeocodeLocation(location, delegate(object[] placemarks, NSError error) { if (error != null) { Debug.Log(error.LocalizedDescription()); } else { foreach (var p in placemarks) { var placemark = p as CLPlacemark; Debug.Log("placemark: " + placemark.name + "\n" + ABAddressFormatting.ABCreateString(placemark.addressDictionary, true)); } } }); } if (GUILayout.Button("Significant location change", GUILayout.ExpandHeight(true))) { if (!CLLocationManager.LocationServicesEnabled() || !CLLocationManager.SignificantLocationChangeMonitoringAvailable()) { Debug.Log("Significant change monitoring not available."); } else { // CLLocationManager manager = new CLLocationManager(); manager.StartMonitoringSignificantLocationChanges(); } } //commented out remove all events and reminders so users don't accidentally remove important events /* * if (GUILayout.Button("remove all Events", GUILayout.ExpandHeight(true))) { * PersonalXT.RemoveAllEvents(); * Log ("Removed events"); * } * * if (GUILayout.Button("remove all Reminders", GUILayout.ExpandHeight(true))) { * PersonalXT.GetAllReminders(); //you can get all the reminders and handle them in line 59 above * //PersonalXT.RemoveAllReminders(); //or you can simply call removeAllReminders * }*/ GUILayout.EndArea(); OnGUILog(); }