zoukankan      html  css  js  c++  java
  • iOS 拨打电话优化

    最近在测试项目发现项目中调用电话的在iOS 10上会出现卡顿,点击调用会有一小段延,现在是这样实现拨打电话的:

    NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",_phoneNum];
            UIWebView *callWebview = [[UIWebView alloc] init];
            [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
            [self.view addSubview:callWebview];

    优化如下:

    + (void)callPhoneStr:(NSString*)phoneStr  withVC:(UIViewController *)selfvc{
        NSString *str2 = [[UIDevice currentDevice] systemVersion];
        
        if ([str2 compare:@"10.2" options:NSNumericSearch] == NSOrderedDescending || [str2 compare:@"10.2" options:NSNumericSearch] == NSOrderedSame)
        {
            NSLog(@">=10.2");
            NSString* PhoneStr = [NSString stringWithFormat:@"tel://%@",phoneStr];
            if ([PhoneStr hasPrefix:@"sms:"] || [PhoneStr hasPrefix:@"tel:"]) {
                UIApplication * app = [UIApplication sharedApplication];
                if ([app canOpenURL:[NSURL URLWithString:PhoneStr]]) {
                    [app openURL:[NSURL URLWithString:PhoneStr]];
                }
            }
        }else {
             NSMutableString* str1 = [[NSMutableString alloc]initWithString:phoneStr];// 存在堆区,可变字符串
            if (phoneStr.length == 10) {
                [str1 insertString:@"-"atIndex:3];// 把一个字符串插入另一个字符串中的某一个位置
                [str1 insertString:@"-"atIndex:7];// 把一个字符串插入另一个字符串中的某一个位置
            }else {
                [str1 insertString:@"-"atIndex:3];// 把一个字符串插入另一个字符串中的某一个位置
                [str1 insertString:@"-"atIndex:8];// 把一个字符串插入另一个字符串中的某一个位置
            }
            NSString * str = [NSString stringWithFormat:@"是否拨打电话 %@",str1];
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:str message: nil preferredStyle:UIAlertControllerStyleAlert];
            // 设置popover指向的item
            alert.popoverPresentationController.barButtonItem = selfvc.navigationItem.leftBarButtonItem;
            // 添加按钮
            [alert addAction:[UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
                NSLog(@"点击了呼叫按钮10.2下");
                NSString* PhoneStr = [NSString stringWithFormat:@"tel://%@",phoneStr];
                if ([PhoneStr hasPrefix:@"sms:"] || [PhoneStr hasPrefix:@"tel:"]) {
                    UIApplication * app = [UIApplication sharedApplication];
                    if ([app canOpenURL:[NSURL URLWithString:PhoneStr]]) {
                        [app openURL:[NSURL URLWithString:PhoneStr]];
                    }
                }
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                NSLog(@"点击了取消按钮");
            }]];
            [selfvc presentViewController:alert animated:YES completion:nil];
        }
        
    }

  • 相关阅读:
    Python3 tkinter基础 Radiobutton variable 默认选中的按钮
    oracle函数NVL,NVL2和NULLIF之间的区别和使用
    js如何返回两个数的商的整数和余数部分?
    解决win10打开组策略弹出管理模板对话框问题
    asp.net mvc中动作方法的重定向
    asp.net mvc如何获取url的相关信息
    vs2015如何使用附加进程调试发布在IIS上项目
    未能加载文件或程序集“Oracle.DataAccess”或它的某一个 依赖项。如何解决?
    C#中使用SqlBulkCopy的批量插入和OracleBulkCopy的批量插入
    oracle中计算两个日期的相差天数、月数、年数、小时数、分钟数、秒数等
  • 原文地址:https://www.cnblogs.com/LynnAIQ/p/6392496.html
Copyright © 2011-2022 走看看