国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

ios學習筆記之-點擊一個按鈕彈出撥打電話提示框

2019-11-06 09:57:45
字體:
來源:轉載
供稿:網友

按鈕的代碼就不寫了。直接寫主要代碼。

<key>LSapplicationQueriesSchemes</key><array><string>tel</string><string>telPRompt</string></array>

plist里加上述代碼就是意思申請打電話權限

-(void)callPhoneStr:(NSString*)phoneStr  {

    NSString *str2 = [[UIDevicecurrentDevice] systemVersion];

    

    if ([str2compare:@"10.2"options:NSNumericSearch] ==NSOrderedDescending || [str2compare:@"10.2"options:NSNumericSearch] ==NSOrderedSame)

    {

        NSLog(@">=10.2");

        NSString* PhoneStr = [NSStringstringWithFormat:@"tel://%@",phoneStr];

        if ([PhoneStrhasprefix:@"sms:"] || [PhoneStrhasPrefix:@"tel:"]) {

            UIApplication * app = [UIApplicationsharedApplication];

            if ([appcanOpenURL:[NSURLURLWithString:PhoneStr]]) {

                [app openURL:[NSURLURLWithString:PhoneStr ]options:@{}completionHandler:nil                                                                                ];

              

            }

        }

    }else {

        NSMutableString* str1 = [[NSMutableStringalloc]initWithString:phoneStr];//存在堆區,可變字符串

     

        NSString * str = [NSStringstringWithFormat:@"是否撥打電話/n%@",str1];

        UIAlertController *alert = [UIAlertControlleralertControllerWithTitle:strmessage: nilpreferredStyle:UIAlertControllerStyleAlert];

      

        [alert addAction:[UIAlertActionactionWithTitle:@"呼叫"style:UIAlertActionStyleDestructivehandler:^(UIAlertAction *action) {

            NSLog(@"點擊了呼叫按鈕10.2下");

            NSString* PhoneStr = [NSStringstringWithFormat:@"tel://%@",phoneStr];

            if ([PhoneStrhasPrefix:@"sms:"] || [PhoneStrhasPrefix:@"tel:"]) {

                UIApplication * app = [UIApplicationsharedApplication];

                if ([appcanOpenURL:[NSURLURLWithString:PhoneStr]]) {

                    [app UIApplication:[NSURLURLWithString:PhoneStr]];

                }

            }

        }]];

        [alert addAction:[UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction *action) {

            NSLog(@"點擊了取消按鈕");

        }]];

        [selfpresentViewController:alertanimated:YEScompletion:nil];

    }

    

}

一定要區分一下ios系統版本,因為api是不一樣的,因為版本不一樣,方法是不一樣的。10.2那個里面的方法自己可以彈出一個彈出框,另外一個需要用UIAlertController來制作彈出框。

這里推薦一個

http://www.cocoachina.com/ios/20161021/17824.html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 岚皋县| 中牟县| 五河县| 曲靖市| 中阳县| 城固县| 无锡市| 象州县| 建湖县| 射阳县| 苏尼特左旗| 搜索| 正宁县| 新民市| 阳山县| 莱西市| 通州区| 镇康县| 茂名市| 阿拉善左旗| 丰宁| 天长市| 南江县| 昌吉市| 睢宁县| 临颍县| 涞水县| 太湖县| 徐水县| 绥德县| 桑植县| 四川省| 肇东市| 普兰店市| 栾川县| 专栏| 金门县| 阿鲁科尔沁旗| 静安区| 杭锦后旗| 宝丰县|