跳到主要內容

Xcode iOS 打電話功能

 


方法一

1.這種方法,網上很多說法是,撥打完,電話。回不到原來的應用,會停留在通訊錄裡,而且是直接撥打,不彈出提示

但本人在iOS 10.3測試是,有 提示框的。也會回到原來的應用。其他版本系統沒有測試過。

喚起提示框,很略慢。


    NSString *telephoneNumber=@"撥打的號碼";

    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",telephoneNumber];

    UIApplication *application = [UIApplication sharedApplication];

    NSURL *URL = [NSURL URLWithString:str];

    [application openURL:URL];


方法二

這種方法,打完電話後還會回到原來的程序,也會彈出提示

但本人在iOS 10.3測試,喚起提示框,很略慢。


  NSString *telephoneNumber=@"撥打的號碼";

    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",telephoneNumber];

    UIWebView * callWebview = [[UIWebView alloc] init];

    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];

    [self.view addSubview:callWebview];

    [callWebview release];

    [str release];


方法三

這種方法也會回去到原來的程序裡(注意這裡的telprompt),也會彈出提示

但本人在iOS 10.3測試,喚起提示框,很略慢。


  NSString *telephoneNumber=@"撥打的號碼";

    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",telephoneNumber];

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]


方法四

打完電話後還會回到原來的程序,也會彈出提示

前面的三種方法都會有⚠️,提示ios10後不再推薦使用。

官方,iOS 10之後推薦使用下面的方法

但本人在iOS 10.3測試,喚起提示框,比前面三種方法快。


     NSString *telephoneNumber=@"撥打的號碼";

     NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",telephoneNumber];

    UIApplication *application = [UIApplication sharedApplication];

    NSURL *URL = [NSURL URLWithString:str];

    [application openURL:URL options:@{} completionHandler:^(BOOL success) {

        //OpenSuccess=選擇 呼叫 為 1 選擇 取消 為0

        NSLog(@"OpenSuccess=%d",success);

    

    }];

留言

這個網誌中的熱門文章

PHP 登入網站示例 By ChatGPT

  PHP 登入網站示例 By ChatGPT 以下是一個簡單的 PHP 登入網站示例,包括登入頁面、驗證登入、登出功能: index.php (登入頁面) login.php (驗證登入) php <?php session_start ();  // 模擬用戶名和密碼,實際情況下需從數據庫或其他來源驗證 $valid_username = 'user' ; $valid_password = 'password' ;  // 檢查用戶提交的用戶名和密碼   if ( isset ( $_POST [ 'username' ], $_POST [ 'password' ]))  {  $username = $_POST [ 'username' ];  $password = $_POST [ 'password' ];  // 驗證用戶名和密碼是否正確   if ( $username === $valid_username && $password === $valid_password )  {  // 設置用戶會話   $_SESSION [ 'username' ] = $username ;  header ( 'Location: dashboard.php' );  // 登入成功,重定向到用戶主頁 exit ();   }  else   {  echo '用戶名或密碼錯誤' ;   }  }  ?> dashboard.php (用戶主頁) php Copy code <?php session_start ();  // 檢查用戶是否已登入,否則重定向到登入頁面   if (! isset ( $_SESSION [ 'username' ]))  {  header ( 'Location: index.php' );  exit ();  }  // 顯示用戶名 ...

PHP + MySQL 範例 By ChatGPT

  PHP + MySQL 範例 By ChatGPT 以下是一個簡單的 PHP + MySQL 範例,演示如何建立一個簡單的使用者註冊系統: 首先,創建一個名為 register.php 的 PHP 檔案,用於顯示註冊表單和處理用戶提交的註冊信息。 php <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "UTF-8" > <title>User Registration</title> </head> <body> <h2>User Registration</h2> <form action= "register.php" method= "post" > <label for = "username" >Username:</label> <input type= "text" id= "username" name= "username" required><br><br> <label for = "password" >Password:</label> <input type= "password" id= "password" name= "password" required><br><br> <input type= "submit" value= "Register" > </form> <?php // 如果是 POST 請求,處理用戶註冊 if ( $_S...

[轉貼] 如何正確設定 AFNetworking 的安全連線

如何正確設定 AFNetworking 的安全連線 TL;DR 前一陣子  AFNetworking  被爆出存在安全性漏洞,它們也針對這件事情發出 聲明稿 。 簡單的說,就是建議開發者使用最新版的 AFNetworking,並且啟用安全連線。不過它們也承認這一部份的說明文件沒有寫得很齊全,所以困擾了不少開發者。 今天花了一點時間研究,順手把它記錄下來。安全相關的東西不是我的專長,所以如果有任何錯誤的地方,請留言告訴我。 取得安全憑證 1. 確認有使用安全連線 如果你跟遠端伺服器是透過 HTTP 連線,那就不是安全連線,如果是 HTTPS 那就是安全連線。 2. 準備好網站的安全憑證 接下來我們需要憑證檔(Certification file),它的副檔名是  .cer ,你可以跟你們的網站管理員詢問,通常他們都知道怎麼拿到這個檔案。 如果你的網站管理員沒有  .cer  檔,只有  .crt  檔,那你可以透過以下這行指令轉檔,要注意的是它是採用  DER  編碼格式(請自行將  myWebsite  替換成你想要的名字): openssl x509 -in myWebsite.crt -out myWebsite.cer -outform der 如果很不幸的,你的網站管理員連  .crt  檔都沒有,那你也可以使用下列這一整行指令從你們的網站取得憑證(請自行將  www.mywebsite.com  替換成你們的網址): openssl s_client -connect  www . mywebsite . com : 443  </dev/null 2>/dev/null | openssl x509 -outform DER > myWebsite.cer 現在你有一個憑證檔了。 3. 將憑證加入你的專案 將你的憑證拖拉放到 Xcode 專案底下,記得要把  Copy items if needed  跟  Add to targets  打勾。 好了,事前準備都做完,接著我們來設定 AFNetworking。 設定 AFNetwo...