Ios 根据用户的位置,拨打不同号码的电话
我正在开发一个应用程序,能够感知用户的位置,然后根据位置拨打特定的电话号码 我用这个方法打电话, -IBActionphone{[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@tel:123]] 然后我有这个方法来获取用户的位置Ios 根据用户的位置,拨打不同号码的电话,ios,cllocationmanager,Ios,Cllocationmanager,我正在开发一个应用程序,能够感知用户的位置,然后根据位置拨打特定的电话号码 我用这个方法打电话, -IBActionphone{[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@tel:123]] 然后我有这个方法来获取用户的位置 NSLog(@"Resolving the Address"); [geocoder reverseGeocodeLocation:currentLocation completionHa
NSLog(@"Resolving the Address");
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
_addressLabel.text = [NSString stringWithFormat:@"%@ %@\n%@ %@\n%@\n%@",
placemark.subThoroughfare, placemark.thoroughfare,
placemark.postalCode, placemark.locality,
placemark.administrativeArea,
placemark.country];
} else {
NSLog(@"%@", error.debugDescription);
}
} ];
根据用户的placemark.locality,我想拨打其他号码。
有什么想法吗?
提前感谢您假设这是一个最佳实践问题: 映射到NSDictionary,然后选择by placemark.locality,然后进行调用
NSDictionary *map = @{
@"New York" : @"+1 212-226-3126",
@"San Francisco" : @"+1 415-392-0202"
};
if ([[map allKeys] containsObject:placemark.locality])
{ phoneNumber = [map objectForKey:placemark.locality]; }
您可以使用NSDictionary映射带有电话号码的地点,例如:
NSDictionary *localityToPhoneNumber = @{"Paris": @"+338123710", @"London": @"+412345678"};
然后,您可以获取属于某个地区的电话号码并拨打:
NSString *phoneNumber = [localityToPhoneNumber objectForKey:placemark.locality];
NSString *tel = [NSString stringWithFormat:@"tel:%@", phoneNumber];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:tel];