iphone - 发送文本然后调用联系人 iPhone 应用程序

标签 iphone ios objective-c

我有一个紧急调用应用程序。当用户按下联系人时,它会调用他们。然后用户必须返回到应用程序以发送自动短信。但是我希望当按下联系人时,用户会被带到消息框架,一旦按下发送,它就会调用该人。这是到目前为止的代码。

- (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]);
}

对此的任何解决方案将不胜感激。

最佳答案

你在做:

messageComposer.messageComposeDelegate = self;

只需定义:

messageComposeViewController:didFinishWithResult

当有人完成编辑文本时调用它,您可以从第二个参数中获取结果。

MessageComposeResultCancelled,
MessageComposeResultSent,
MessageComposeResultFailed

您可以从这个回调中调用电话。

调用电话:

NSString *phoneNumber = [@"telprompt://" stringByAppendingString:@"123123123"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

或 tel://用于在没有提示的情况下调用电话。

关于iphone - 发送文本然后调用联系人 iPhone 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18745137/

相关文章:

ios - 在 Swift 中使用 Alamofire 时如何获取响应头?

iOS 8 UIWebview 委托(delegate) : WebKit discarded an uncaught exception in the webView:didFinishLoadForFrame:

ios - 为 Phonegap/Cordova iPhone 应用程序设置 CMS

html - Objective-C 认证

objective-c - 圆形 CALayer 周围的边框较深

iphone - 如何在cocos2d中创建透明的ccscene?

iphone - 触摸并下拉 View

ios - 无效的 bundle 结构 - 不包括有效负载目录

objective-c - 当控件成为关键时我如何收到通知?我想让我的自定义警告弹出窗口 NSWindow 自动隐藏和显示;只有隐藏部分有效

iphone - 在 iPad 应用程序中更改 UITabbar 项目的宽度和它们之间的边距