加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xcode – 通过短信发送当前位置

发布时间:2020-12-14 17:21:25 所属栏目:百科 来源:网络整理
导读:我正在尝试让我的应用程序能够通过短信将其当前的GPS位置发送到预先输入的电话号码. 我现在有我的代码,只在应用程序内部显示一个SMS窗口,我可以在其中编辑接收号码和正文.我想知道的是我如何得到这个机构的当前位置,以便它可以通过短信发送?无法弄清楚. 这
我正在尝试让我的应用程序能够通过短信将其当前的GPS位置发送到预先输入的电话号码.

我现在有我的代码,只在应用程序内部显示一个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];
    }
}

解决方法

首先在您的项目中添加核心位置框架.并调用此方法来查找当前位置.

-(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",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;

    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读