美文网首页UIiOSiOS进阶指南
APP拨号与发短信功能

APP拨号与发短信功能

作者: 徐老茂 | 来源:发表于2015-12-05 16:54 被阅读438次

在很多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.
希望这个能对你们有用.祝大家开心😄

相关文章

  • APP拨号与发短信功能

    在很多APP里面有拨号功能,比如在美团外卖上面可以点击商家电话后给商家打电话,今天要做的就是这个功能.这个功能其实...

  • iOS-发短信

    在APP内如何发短信呢? MFMessageComposeViewController这个类提供了发短信的功能。 例子

  • 2018-04-10

    1.一键拨号 马上拨打电话10086 2.发短信 发短息

  • ITelephony.endCall 混淆后挂断电话失败

    android开发中定制系统app,自定义拨号打电话功能,在混淆后发现ITelephony.endCall返回的是...

  • Android 电话拨号器

    安卓系统一般自带有:电话,邮件,浏览器功能;本文章简单,讲解电话自带的电话拨号功能进行,电话拨号。 电话拨号器的:...

  • Linux命令之网络通讯命令

    dip 功能说明:IP拨号连接。语法:dip [-aikltv][-m][-p<协议>][拨号scr...

  • iOS手机打电话、发短信功能

    一、实现发短信功能 1、发短信需要遵守导入框架并协议 2、在需要发短信的方法中调用下面代码 3、实现发短信的方法 ...

  • Axure RP 9 教程—设置键盘快捷键

    很早之前写过模拟手机拨号,今天我们在模拟拨号键盘的原型基础上做一个小功能,设置按下电脑键盘上的按钮,触发拨号的交互...

  • a链接常用功能

    一、页面中调用qq 二、页面中调用拨号 三、下载功能

  • iOS常用小功能

    iOS中很多小功能都是非常简单的,几行代码就可以实现,比如打电话、发短信、发邮件、应用评分、跳转App Store...

网友评论

    本文标题:APP拨号与发短信功能

    本文链接:https://www.haomeiwen.com/subject/uvnshttx.html