2013-01-19 15 views
6

UIActivityViewControllerは、画像とテキストを共有するのに最適です。どのように場所を共有することができますか?画像とテキストを共有するには、対応するオブジェクトをNSArrayに追加します。これをUIActivitiesとして渡します。 CLLocationCoordinate2Dを追加したいだけですが、それはオブジェクトではなく構造体です。UIActivityViewControllerを使用して場所を共有するにはどうすればいいですか?

答えて

1

私は同じ問題を抱えていましたが、UIActivityViewControllerを使って座標を取得する答えを見つけることができませんでした。

回避策として、WhatsAppで使用されているのと同様のアプローチを使用しました。そこでは、異なるマッププロバイダを使用してアクションシートを取得します。次のコードでは警告が表示され、Waze/Google Maps/Apple Mapsから特定の場所を開くことができます。インストールされているアプリのみが表示されます。ちょうど "経度"と "緯度"の値をあなたのCLLocationCoordinate2D緯度/経度プロパティで置き換えてください。

UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; 

UIAlertAction* appleMaps = [UIAlertAction actionWithTitle:@"Open in Maps" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.apple.com/?q=%@,%@", latitude, longitude]]]; 
     }]; 
UIAlertAction* googleMaps = [UIAlertAction actionWithTitle:@"Open in Google Maps" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"comgooglemaps://?q=%@,%@", latitude, longitude]]]; 
     }]; 
UIAlertAction* waze = [UIAlertAction actionWithTitle:@"Open in Waze" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"waze://?ll=%@,%@", latitude, longitude]]]; 
     }]; 

[alert addAction:appleMaps]; 
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) 
      [alert addAction:googleMaps]; 
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"waze://"]]) 
      [alert addAction:waze]; 


UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:nil]; 

[alert addAction:cancel]; 

[self presentViewController:alert animated:YES completion:nil]; 
関連する問題