zoukankan      html  css  js  c++  java
  • iOS中调用系统打电话

    先介绍一种最简单的方法:

    调用打电话功能

    [[UIApplicationsharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];

    调用发短信功能

    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://10000"]];


    上面的发短信的功能是调用系统的界面,下面是实现一种点击按键就直接发送短信,相当于后台发送,能不能上软件商店,还不能确定。相对建议来说,尽量使用第一种。


    首先导入MFMessageComposeViewControllerDelegate这个代理,实现里面的方法

    -(void)messageComposeViewController:(MFMessageComposeViewController *)controllerdidFinishWithResult:(MessageComposeResult)result {

         

          //Notifies users about errors associated with the interface

          switch (result) {

             case MessageComposeResultCancelled:

                if (DEBUG)NSLog(@"Result: canceled");

                break;

             case MessageComposeResultSent:

                if (DEBUG)NSLog(@"Result: Sent");

                break;

             case MessageComposeResultFailed:

                if (DEBUG)NSLog(@"Result: Failed");

                break;

             default:

                break;

          }

          [self dismissModalViewControllerAnimated:YES];

    }

    群发短信:

    - (IBAction)sendSMS {

         

          BOOL canSendSMS = [MFMessageComposeViewControllercanSendText];

          NSLog(@"can send SMS [%d]",canSendSMS);

          if (canSendSMS) {

         

             MFMessageComposeViewController *picker = [[MFMessageComposeViewControlleralloc] init];

             picker.messageComposeDelegate =self;

             picker.navigationBar.tintColor = [UIColorblackColor];

             picker.body = @"test";

             picker.recipients = [NSArrayarrayWithObject:@"10086"];

             [self presentModalViewController:picker animated:YES];

             [picker release];   

          } 

    }

    给一个人发短信:
    从网页上获得内容

    -(void)displaySMSComposerSheet

    {

        MFMessageComposeViewController *picker = [[MFMessageComposeViewControlleralloc] init];

        picker.messageComposeDelegate =self;

        UIWebView *web = nil;

        NSMutableString* absUrl = [[NSMutableStringalloc] initWithString:web.request.URL.absoluteString];

        [absUrl replaceOccurrencesOfString:@"http://i.aizheke.com"withString:@"http://m.aizheke.com"options:NSCaseInsensitiveSearchrange:NSMakeRange(0, [absUrllength])];

        picker.body=[NSStringstringWithFormat:@"我在爱折客上看到:%@可能对你有用,推荐给你!link:%@",[webstringByEvaluatingJavaScriptFromString:@"document.title"],absUrl];

       [absUrl release];

       [self presentModalViewController:picker animated:YES];

       [picker release];

    }

    事件绑定发送短信

    -(IBAction)showSMSPicker:(id)sender {

        Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));

        if (messageClass != nil) {

            if ([messageClass canSendText]) {

                [self displaySMSComposerSheet];

            }

            else {

    //设备没有短信功能

           }

        }

        else {

    // iOS版本过低,iOS4.0以上才支持程序内发送短信

        }

    }

  • 相关阅读:
    LeetCode 515. 在每个树行中找最大值(Find Largest Value in Each Tree Row)
    LeetCode 114. 二叉树展开为链表(Flatten Binary Tree to Linked List)
    LeetCode 199. 二叉树的右视图(Binary Tree Right Side View)
    LeetCode 1022. 从根到叶的二进制数之和(Sum of Root To Leaf Binary Numbers)
    LeetCode 897. 递增顺序查找树(Increasing Order Search Tree)
    LeetCode 617. 合并二叉树(Merge Two Binary Trees)
    LeetCode 206. 反转链表(Reverse Linked List) 16
    LeetCode 104. 二叉树的最大深度(Maximum Depth of Binary Tree)
    LeetCode 110. 平衡二叉树(Balanced Binary Tree) 15
    LeetCode 108. 将有序数组转换为二叉搜索树(Convert Sorted Array to Binary Search Tree) 14
  • 原文地址:https://www.cnblogs.com/lixiong-iOS/p/3557533.html
Copyright © 2011-2022 走看看