-(IBAction)SendTextTapped:(id)sender{
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController* messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
__block NSString *fullA = [[NSString alloc] init];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
CLLocation *newerLocation = [[CLLocation alloc]initWithLatitude:21.1700
longitude:72.8300];
[geocoder reverseGeocodeLocation:newerLocation
completionHandler:^(NSArray *placemarks, NSError *error) {
if (error) {
NSLog(@"Geocode failed with error: %@", error);
return;
}
if (placemarks && placemarks.count > 0)
{
CLPlacemark *placemark = placemarks[0];
NSDictionary *addressDictionary =
placemark.addressDictionary;
NSLog(@"%@ ", addressDictionary);
NSString *address = [addressDictionary
objectForKey:(NSString *)kABPersonAddressStreetKey];
NSString *city = [addressDictionary
objectForKey:(NSString *)kABPersonAddressCityKey];
NSString *state = [addressDictionary
objectForKey:(NSString *)kABPersonAddressStateKey];
NSString *zip = [addressDictionary
objectForKey:(NSString *)kABPersonAddressZIPKey];
NSLog(@"%@ %@ %@ %@", address,city, state, zip);
//NSLog(fullA);
fullA=(@"%@ %@ %@ %@", address,city, state, zip);
}
}];
[messageController setBody:fullA];
[self presentModalViewController:messageController animated:YES];
}
else {
NSLog(@"%@" , @"Sorry, you need to setup mail first!");
}
}
我嘗試過使用__block或在線教程中找到的所有東西。MessageController(文本)設置主體不設置主體。 (iOS 6)
這確實打印出NSLog中的完整地址。但是,不管是什麼我已經試過這不露面[messageController setBody:(@"%@ %@ %@ %@",city, state, address, zip)];
和使用(setBody:@「你好」)的作品就好了... ...
我敢肯定,有一些小的,我可以做解決這個問題,但我所嘗試過的一切都失敗了。任何想法都會很棒!
還請記住,該地址查找可能需要一些時間。你可能想要顯示一個活動指示器(或類似的東西),讓用戶知道發生了什麼。否則,在點擊按鈕和出現消息編輯器之間可能會有很長的延遲。事實上,用戶可以離開當前的視圖控制器,這可能會導致崩潰。 – rmaddy 2013-03-08 19:45:28