我有一个紧急呼叫应用程序。当用户按下联系人时,它会调用它们。然后用户必须返回应用程序以发送自动SMS。但是我希望当按下联系人时,用户被带到消息框架,一旦按下发送,它就会调用该人。这是迄今为止的代码。
- (NSString *)deviceLocation {
return [NSString stringWithFormat:@"Hi, you have been contacted as there has been an emergancy. Here is the location of the caller: Latitude: %f Longitude: %f . Please call for help to that location. From Kiddy Call the iPhone app. ", locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude];
}
#pragma mark - PictureListMainTableCellDelegate methods
-(void)pictureListMainTableCell:(PictureListMainTableCell *)cell wantsToCallNumber:(NSString *)number
{
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *messageComposer =
[[MFMessageComposeViewController alloc] init];
NSString *message = (@"%@", [self deviceLocation]);
[messageComposer setBody:message];
messageComposer.recipients = [NSArray arrayWithObjects:number , nil];
messageComposer.messageComposeDelegate = self;
[self presentViewController:messageComposer animated:YES completion:nil];
NSLog(@"Texting telephone number [%@]", messageComposer);
}
NSString *urlString = [NSString stringWithFormat:@"tel://%@", number];
NSLog(@"calling telephone number [%@]", number);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
NSLog(@"%@", [self deviceLocation]);
}
非常感谢任何解决方案。
答案 0 :(得分:3)
你在做:
messageComposer.messageComposeDelegate = self;
只需定义:
messageComposeViewController:didFinishWithResult
当有人完成编辑文本时会调用它,你可以从第二个参数中获得结果。
MessageComposeResultCancelled,
MessageComposeResultSent,
MessageComposeResultFailed
通过此回调,您可以拨打电话。
拨打电话:
NSString *phoneNumber = [@"telprompt://" stringByAppendingString:@"123123123"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
或tel://用于在没有提示的情况下进行呼叫。