I'm quite new to iOS development and I'm currently building my first app.
I'm trying to get a text field to automatically populate the telephone country code for a specific country.
So if for example the user picks "UK" he gets "+44" inserted automatically into that text field.
Currently I'm struggling a way to find how to get the exact country telephone code for the country.
I could create an NSDictionary with all of the countries and country telephone code but I thought there might be a better way.
If your goal is to get the dialling code of the user's current location then you should use HMDiallingCode.
It uses CoreLocation and reverse geocoding to get current country of the user and then retrieve it's dialling code.
I think, you can only get country code for the current Carrier using CoreTelephony framework:
CTTelephonyNetworkInfo *info = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = info.subscriberCellularProvider;
NSLog(#"country code is: %#", carrier.mobileCountryCode);
If you need a full list of codes for all countries, you need to use some online service for querying it.
I'm afraid there is not a better way. My app include a .plist file with the array of countries with name, code, phone code, trunk code, etc for each. You will not get all that info from iOS API.
If you only need the international phone code for a country code, here you are a link with a complete table.
Related
I have code to fetch and display User data from Contacts (various Name properties plus the array of Phone numbers). By making a CNMutableContact, I can update any of the Name properties. But I can only display Phone numbers (from CNLabeledValue via ".digits"). Is it possible to also update Phone numbers? I can't change "digits" in the CNMutableContact because it is 'read-only'. I have seen and understand cautions on accessing CNLabeledValue "digits", but would still like to proceed.
Suggestions?
Maybe is a little late to answer this question. However, on the given exemple, you can only add phone numbers. So, to update phone you would, at best, replace removing phone numbers and add new ones.
Replacing a phonenumber entry in this approach would result in changing the phonenumber's identifier.
This should be not the behaviour you are expecting, since you are changing a phone number of an existing entry. And we want to keep the phone identifier intact.
You should use settingValue from CNLabeledValue see: Apple Documentation
// Clone to a mutable contact
let mutableContact = contact.mutableCopy() as! CNMutableContact
// Here's the catch
let updatedPhone = mutableContact.phoneNumbers[0].settingValue(CNPhoneNumber(stringValue: "newPhone"))
// Be aware that in this example, I only have on phone number. For multiple phones, would need to handle multiple phones properly in the array.
mutableContact.phoneNumbers = [updatedPhone]
I am trying to obtain all related contacts to a selected contact. The way to do this seems to be via mycontact.contactRelations. This gives an array of CNLabeledValue with each of those containing a CNContactRelation as their value. There is then a name property, but it appears nothing else.
The Xamarin documentation for CNContact.ContractRelations seems to suggest I should be able to obtain the corresponding CNContact from a CNContactRelation but I can see no way to do this in objc, other than searching for a contact with a matching name. This may or may not be the contact I'm after, even if they also have a relationship to a contact with the same name as mycontact.
The identifier on the CNLabeledValue seems to refer to the label rather than the related contact, or at least doesn't seem to match the identifier if I select that contact from a CNContactPickerViewController.
Is there a way to obtain the CNContact for the related contact in objc ?
The related names field in Contacts doesn't store linkages, just names. You'll notice this from a user perspective if you go to edit related names in the iOS or OS X Contacts app — it's just a freeform text field. Those apps (and other system apps) will recognize when a related name matches that of another contact (which is why you can ask Siri to call your mother, etc), but they also let you put down names for people you don't have contact info for.
So a CNContactRelation just contains a string, and the only way to find (if there are any) contacts matching a related name is to search the contact store. Use unifiedContactsMatchingPredicate:keysToFetch:error: to search, with a predicate constructed by calling predicateForContactsMatchingName:.
I've got the GPS coordinates of a place and want to query the GoogleMaps SDK for the Place ID in order to get more information about a place.
I looked up the documentation https://developers.google.com/places/place-id. But yet didn't found a way on 'easily' get the Place ID like:
let placeId = GMSService.getPlaceIdFromCoordinates(longitude: 02.52324, latitude: 03.5345)
The iOS documentation for Maps and Places API doesn't list GMSService, the only class resembling is is GMSServices which doesn't have the getPlaceIdFromCoordinates.
You can look at the Place IDs and Details of the Places API documentation. PlaceID can be retrieved from the GMSPlace object.
To actually search for places (whether through text or coordinates) you can try out the Place Autocomplete page of the documentation.
In my ios app i'm using this call to get an autocomplete function
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%#&types=(cities)&key=%s
After that i use another call to retrive details of a place starting by his placeid:
https://maps.googleapis.com/maps/api/place/details/json?placeid=%#&key=%s&language=en&oe=utf8
Now i need to store in my app the city name in localized format (english,italian,french,spanish). I think that i can made a localized place-detail each language i wanna support but i would like to retrive this information with the minimum number of requests. There's a way to get all the localized name of a city starting by his placeid?
I might be wrong on this, but it seems like you can only set one lanugage in the language parameter. Yet, even with that you should be able to make multiple calls like
var langIDs = ["en","it","fr","de","es"];
for(var langID in langIDs){
url = "http://maps.googleapis.com/maps/api/directions/json?origin=34.431741,135.392299&destination=34.631741,135.992299&sensor=false&language=" + langIDs[langID]+ "&";
}
Note, I did not test the code.
Thank
I am using the MKLocalSearchRequest class to allow the user to search for an address in my app.
I dont want the response results to contain businesses. Is there any way I can tell the class/API not to return businesses in the response?
Thanks
Unless you can specify it in the naturalLanguageQuery portion of the MKLocalSearchRequest then it doesn't appear that the MKMapItem actually stores whether it's a business. The Apple documentation does say the phoneNumber should be used for a business but whether that's a guaranteed for all locations is an unknown.