Send current location through an SMS

后端 未结 1 882
不思量自难忘°
不思量自难忘° 2021-02-06 15:44

I\'m trying to get my app to be able to send its current GPS location through an SMS to a preentered phone number.

I have my code right now that only brings up an SMS w

相关标签:
1条回答
  • 2021-02-06 16:30

    Firstly add core location framework in Your Project. and call this method for finding current location.

     -(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 讨论(0)
提交回复
热议问题