打电话-方法3
创建一个UIWebView来加载URL,拨完后能自动回到原应用
if(_webView==nil) {
_webView= [[UIWebViewalloc]initWithFrame:CGRectZero];
}
[_webViewloadRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:@"tel://10010"]]];
拨号之前会弹框询问用户是否拨号,拨完后能自动回到原程序.
注意:这个webView千万不要设置尺寸,不然会挡住其他界面,他只是用来打电话,不需要显示
发短信-方法2
如果想指定短信内容,那就得使用MessageUI框架,包含主头文件
显示发短信的控制器(不会跳出当前控制器)
MFMessageComposeViewController*vc = [[MFMessageComposeViewControlleralloc]init];
设置短信内容
vc.body=@"吃饭了没?";
设置收件人列表
vc.recipients=@[@"10010",@"02010010"];
设置代理
vc.messageComposeDelegate=self;
显示控制器
[selfpresentViewController:vcanimated:YEScompletion:nil];
代理方法,当短信界面关闭的时候调用,发完后会自动回到原应用
#pragma mark MFMessageComposeViewControllerDelegate
- (void)messageComposeViewController:(MFMessageComposeViewController*)controller didFinishWithResult:(MessageComposeResult)result{
switch(result) {
case MessageComposeResultCancelled:
NSLog(@"取消发送!");
break;
case MessageComposeResultSent:
NSLog(@"发送成功!");
break;
case MessageComposeResultFailed:
NSLog(@"发送失败!");
break;
default:
break;
}
[controllerdismissViewControllerAnimated:YES completion:nil];
}
邮件发送后的代理方法回调,发完后会自动回到原应用
发邮件方法二
/**
*注释:发送邮件,不会跳出当前应用
*/
- (void)sendeEmail
{
MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
mailPicker.mailComposeDelegate = self;
[mailPickersetSubject:@"eMail主题"];
//NSArray *toRecipients = [NSArray arrayWithObject: @"first@example.com",@"2@qq.com"];
NSArray*toRecipients =@[@"1@qq.com",@"2@qq.com"];
[mailPickersetToRecipients: toRecipients];
[self presentViewController:mailPicker animated:YES completion:nil];
}
#pragma mark MFMailComposeViewControllerDelegate
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
if(error) {
NSLog(@"error :%@",error);
}
if (result == MFMailComposeResultSent) {
}
switch(result) {
case MFMailComposeResultCancelled:
NSLog(@"取消发送!");
break;
case MFMailComposeResultFailed:
NSLog(@"发送失败!");
break;
case MFMailComposeResultSaved:
NSLog(@"保存发送!");
break;
case MFMailComposeResultSent:
NSLog(@"发送成功!");
break;
default:
break;
}
[controllerdismissViewControllerAnimated:YES completion:nil];
}
打开其他常见文件
如果想打开一些常见文件,比如html、txt、PDF、PPT等,都可以使用UIWebView打开.只需要告诉UIWebView文件的URL即可.至于打开一个远程的共享资源,比如http协议的,也可以调用系统自带的Safari浏览器:
NSURL*url = [NSURLURLWithString:@”http://www.baidu.com"];
[[UIApplicationsharedApplication]openURL:url];
打开AppStore(跳出当前应用)
为了提高应用的用户体验,经常需要邀请用户对应用进行评分.应用评分无非就是跳转到AppStore展示自己的应用,然后由用户自己撰写评论.如何跳转到AppStore,并且展示自己的应用:
NSString*appid =@"725296055”;
//https://itunes.apple.com/cn/app/wang-yi-xin-wen/id425349261?mt=8
NSString*str = [NSStringstringWithFormat:
@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8", appid];
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:str]];
打开AppStore(不跳出当前应用)
/**
*注释:打开AppStore,不会跳出当前应用
*/
- (void)sendeAppStore{
SKStoreProductViewController *viewController =[[SKStoreProductViewController alloc] init];
viewController.delegate=self;
//这里的425349261是某一个应用的id(每一个用用程序都会配一个id)
//这个id怎么获取:打开iTunes,找到某一个应用(点进去),在应用的旁边有一个按钮,点击按钮有个复制链接,把链接复制出来,里面有一个id。
NSDictionary *dict = [NSDictionary dictionaryWithObject:@"425349261" forKey:SKStoreProductParameterITunesItemIdentifier];
[viewControllerloadProductWithParameters:dictcompletionBlock:^(BOOLresult,NSError*error) {
if(result) {
NSLog(@"加载成功");
}
if(error) {
NSLog(@"-------%@",error);
}
}];
[self presentViewController:viewController animated:nil completion:nil];
}
- (void)productViewControllerDidFinish:(SKStoreProductViewController*)viewController{
[viewControllerdismissViewControllerAnimated:YES completion:nil];
}