2012-03-12 7 views
4

私は、自分のアプリが現在のGPSの場所をSMSを介して先行する電話番号に送信できるようにしようとしています。現在の場所をSMSで送信する

私は受信中の番号と本文で編集できるアプリ内にSMSウィンドウしか表示されません。私が疑問に思っているのは、SMSを介して送信できるように、この本文の現在の位置を取得する方法です。それを理解できません。

これは私のコードが今SMS機能に関してどのようになっているかを示しています。

-(IBAction) sendInAppSMS:(id) sender 
{ 
    MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease]; 
    if([MFMessageComposeViewController canSendText]) 
    { 
     controller.body = @"Alarm!, call the senders number!"; 
     controller.recipients = [NSArray arrayWithObjects:@"phonenumber1", @"phonenumber2", nil]; 
     [self presentModalViewController:controller animated:YES]; 
    } 
} 
+0

現在位置を取得するためにコアロケーションフレームワークを使用してください。これはあなたのSMS本体に追加することができます –

+1

@Marcus - これを修正できましたか? – Akshay

答えて

1

まず、プロジェクトにコア位置付けフレームワークを追加します。現在の場所を見つけるためにこのメソッドを呼び出します。

-(IBAction) sendInAppSMS:(id) sender 
    { 
     MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease]; 
     if([MFMessageComposeViewController canSendText]) 
     { 
      CLLocation *location=[self findCurrentLocation]; 
      CLLocationCoordinate2D coordinae=[location coordinate]; 
      controller.body =[[NSString alloc] initWithFormat:@" Alarm!, call the senders number with latitude:%f longitude:%f",coordinae.latitude,coordinae.longitude]; ; 
      controller.recipients = [NSArray arrayWithObjects:@"phonenumber1", @"phonenumber2", nil]; 
      [self presentModalViewController:controller animated:YES]; 
     } 
    } 

-(CLLocation*)findCurrentLocation 
      { 

      CLLocationManager *locationManager = [[CLLocationManager alloc] init]; 
      if ([locationManager locationServicesEnabled]) 
      { 
       locationManager.delegate = self; 
       locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
       locationManager.distanceFilter = kCLDistanceFilterNone; 
       [locationManager startUpdatingLocation]; 
      } 

      CLLocation *location = [locationManager location]; 
      CLLocationCoordinate2D coordinate = [location coordinate]; 
     return location; 

    } 
+0

私はコアロケーションフレームワークを追加しました。上記のコードを追加しようとしましたが、3つの問題があります。 1 - 'locationServicesEnabled'は推奨されていません。 2 - 互換性のないタイプ 'ERSSecondViewController *'から 'id 'に割り当てます。 3 - 未使用変数 'c​​oordinate'。何かが欠落しているはずです:Pしかし、IBAction sendInAppSMSに入れるコードは、SMSメッセージの座標を取得するためにどのようなコードが必要ですか?あなたの助けをもう一度感謝します! – Marcus

+0

私は最初の2つの問題/エラーを修正しました。しかし、最後に残っているのは「使用されていない変数」の座標です。しかし、私はそこに行きます:P – Marcus

+0

この行をコメントしてくださいCLLocationCoordinate2D座標= [位置座標];座標を送信する場所でこれを使用してください –