iOS 常用小功能
2016-12-05 15:19
260 查看
小功能简介
iOS中的很多小功能都是非常简单的,几行代码就搞定了,比如打电话、打开网址、发邮件、发短信等
打电话-方法3
创建一个UIWebView来加载URL,拨完后能自动回到原应用
if (_webView ==
nil) {
_webView = [[UIWebView
alloc] initWithFrame:CGRectZero];
}
[_webView
loadRequest:[NSURLRequest
requestWithURL:[NSURL
URLWithString:@"tel://10010"]]];
拨号之前会弹框询问用户是否拨号,拨完后能自动回到原程序
注意:这个webView千万不要设置尺寸,不然会挡住其他界面,他只是用来打电话,不需要显示
发短信-方法2
如果想指定短信内容,那就得使用MessageUI框架
包含主头文件
#import
<MessageUI/MessageUI.h>
显示发短信的控制器
MFMessageComposeViewController *vc = [[MFMessageComposeViewController
alloc] init];
设置短信内容
vc.body
=
@"吃饭了没?";
设置收件人列表
vc.recipients =
@[@"10010",
@"02010010"];
设置代理
vc.messageComposeDelegate =
self;
显示控制器
[self
presentViewController:vc
animated:YES
completion:nil];
代理方法,当短信界面关闭的时候调用,发完后会自动回到原应用
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
关闭短信界面
[controller
dismissViewControllerAnimated:YES
completion:nil];
if (result ==
MessageComposeResultCancelled) {
NSLog(@"取消发送");
}
else if (result == MessageComposeResultSent) {
NSLog(@"已经发出");
}
else {
NSLog(@"发送失败");
}
}
邮件发送后的代理方法回调,发完后会自动回到原应用
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error
{
关闭邮件界面
[controller
dismissViewControllerAnimated:YES
completion:nil];
if (result ==
MFMailComposeResultCancelled) {
NSLog(@"取消发送");
}
else if (result == MFMailComposeResultSent) {
NSLog(@"已经发出");
}
else {
NSLog(@"发送失败");
}
}
打开其他常见文件
如果想打开一些常见文件,比如html、txt、PDF、PPT等,都可以使用UIWebView打开
只需要告诉UIWebView文件的URL即可
至于打开一个远程的共享资源,比如http协议的,也可以调用系统自带的Safari浏览器:
NSURL *url = [NSURL
URLWithString:@”http://www.baidu.com"];
[[UIApplication
sharedApplication]
openURL:url];
应用评分
为了提高应用的用户体验,经常需要邀请用户对应用进行评分,应用评分无非就是跳转到AppStore展示自己的应用,然后由用户自己撰写评论,如何跳转到AppStore,并且展示自己的应用
方法
NSString
*appid =
@"725296055”;
NSString *str = [NSString
stringWithFormat:
@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8", appid];
[[UIApplication
sharedApplication]
openURL:[NSURL
URLWithString:str]];
iOS中的很多小功能都是非常简单的,几行代码就搞定了,比如打电话、打开网址、发邮件、发短信等
打电话-方法3
创建一个UIWebView来加载URL,拨完后能自动回到原应用
if (_webView ==
nil) {
_webView = [[UIWebView
alloc] initWithFrame:CGRectZero];
}
[_webView
loadRequest:[NSURLRequest
requestWithURL:[NSURL
URLWithString:@"tel://10010"]]];
拨号之前会弹框询问用户是否拨号,拨完后能自动回到原程序
注意:这个webView千万不要设置尺寸,不然会挡住其他界面,他只是用来打电话,不需要显示
发短信-方法2
如果想指定短信内容,那就得使用MessageUI框架
包含主头文件
#import
<MessageUI/MessageUI.h>
显示发短信的控制器
MFMessageComposeViewController *vc = [[MFMessageComposeViewController
alloc] init];
设置短信内容
vc.body
=
@"吃饭了没?";
设置收件人列表
vc.recipients =
@[@"10010",
@"02010010"];
设置代理
vc.messageComposeDelegate =
self;
显示控制器
[self
presentViewController:vc
animated:YES
completion:nil];
代理方法,当短信界面关闭的时候调用,发完后会自动回到原应用
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
关闭短信界面
[controller
dismissViewControllerAnimated:YES
completion:nil];
if (result ==
MessageComposeResultCancelled) {
NSLog(@"取消发送");
}
else if (result == MessageComposeResultSent) {
NSLog(@"已经发出");
}
else {
NSLog(@"发送失败");
}
}
邮件发送后的代理方法回调,发完后会自动回到原应用
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error
{
关闭邮件界面
[controller
dismissViewControllerAnimated:YES
completion:nil];
if (result ==
MFMailComposeResultCancelled) {
NSLog(@"取消发送");
}
else if (result == MFMailComposeResultSent) {
NSLog(@"已经发出");
}
else {
NSLog(@"发送失败");
}
}
打开其他常见文件
如果想打开一些常见文件,比如html、txt、PDF、PPT等,都可以使用UIWebView打开
只需要告诉UIWebView文件的URL即可
至于打开一个远程的共享资源,比如http协议的,也可以调用系统自带的Safari浏览器:
NSURL *url = [NSURL
URLWithString:@”http://www.baidu.com"];
[[UIApplication
sharedApplication]
openURL:url];
应用评分
为了提高应用的用户体验,经常需要邀请用户对应用进行评分,应用评分无非就是跳转到AppStore展示自己的应用,然后由用户自己撰写评论,如何跳转到AppStore,并且展示自己的应用
方法
NSString
*appid =
@"725296055”;
NSString *str = [NSString
stringWithFormat:
@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8", appid];
[[UIApplication
sharedApplication]
openURL:[NSURL
URLWithString:str]];
相关文章推荐
- iOS开发之iOS10简单适配
- IOS下的safari下localStorage不起作用的问题以及解决方法
- 追书神器破解版
- 关于iscroll滚动插件,在iOS下面,上拉之后无法回弹的问题
- iOS 触摸事件与手势识别器(Gesture Recognizers)
- iOS 导航栏Title不居中
- runtime使用时-交叉方法简单使用
- ios push卡顿,多次push同一个页面
- xamarin.iOS 设置Label指定文字的颜色
- vmstat和iostat
- IOS设计结构-姬云鹏
- iOS中 @synthesize 和 @dynamic
- iOS 事件的产生、传递、响应
- iOS 常用的反向传值协议的使用
- xamarin.iOS 动态计算表中单元格cell的高度
- iOS图片转成视频方法
- xamarin.iOS 导航栏添加按钮
- 适配 iOS10 以及 Xcode8
- 加速iOS开发的28个第三方库
- xamarin.iOS 滑动视图上添加边缘滑动手势