APP拨号与发短信功能

在很多APP里面有拨号功能,比如在美团外卖上面可以点击商家电话后给商家打电话,今天要做的就是这个功能.这个功能其实非常非常简单,但需要真机运行才可以实现,虚拟机不行.看看代码你们就知道多简单了.

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(100, 100, 175, 50);
    [button setTitle:@"打电话" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor cyanColor];
    [button addTarget:self action:@selector(call) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
    button1.frame = CGRectMake(100, 200, 175, 50);
    [button1 setTitle:@"发短信" forState:UIControlStateNormal];
    button1.backgroundColor = [UIColor cyanColor];
    [button1 addTarget:self action:@selector(sendMessage) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];
}
-(void)call
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];
}
-(void)sendMessage
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://10010"]];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

是不是非常简单?
当你按下打电话button时,手机就会给10086打电话,当你按下发短信button时,手机就会跳转到短信编辑界面,而发送人就是10010.
希望这个能对你们有用.祝大家开心😄

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,573评论 0 17
  • 文章开始前我想先问一个问题,一个十年前我被人问过的问题:在人际交往中,如果可以选择,你希望别人替你买单呢?还是你替...
    兔兔纸阅读 7,935评论 104 74
  • 《西方哲学史》中,罗素终于说到自己致力的领域了,反倒说得很简略,但对逻辑分析哲学派的态度说得很清晰,一部分是借助数...
    Allul阅读 320评论 0 0
  • 舒笑言 ​1948年,入东北电影制片厂第3期训练班,同年任摄影助理,参与了新中国第一部故事片《桥》的拍摄,后拍摄《...
    24号楼阅读 575评论 0 0
  • 不是每个对你微笑的人,都真正的开心。不是每个离开你的爱人,都值得你去怀念。很多时候,爱情都是假象。
    连晓城阅读 96评论 0 0