国产探花免费观看_亚洲丰满少妇自慰呻吟_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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鹤山市| 东乌| 镇江市| 葫芦岛市| 西昌市| 资源县| 肃北| 潜山县| 高清| 称多县| 玛纳斯县| 安国市| 大埔区| 翼城县| 大安市| 彰化县| 烟台市| 绥滨县| 乌鲁木齐市| 彰化市| 涞水县| 额济纳旗| 武宣县| 景宁| 湄潭县| 封丘县| 安陆市| 三都| 贵阳市| 加查县| 新田县| 法库县| 西吉县| 宜兰县| 浮山县| 丰都县| 安义县| 天门市| 淮阳县| 辉县市| 盱眙县|