2011-08-25 29 views
-1

這裏的電話與手機call.After我的應用程序交易google搜索,我發現的代碼從我的應用程序調用用戶使從應用

NSURL *phoneNumber = [[NSURL alloc] initWithString: @"tel:867-5309"]; 
[[UIApplication sharedApplication] openURL: phoneNumber]; 

這是我code.I不知道是怎麼回事在這裏,在撥打電話時,設備使用任何協議,否則代碼將啓動設備的正常撥號功能。

是否強制將Core Telephony Framework添加到我的應用程序?

+0

嘗試移除喜歡多餘的字符 - ,空間,符號等,爲我們的代碼 – Satyam

回答

3

試試這個

哪裏pPhoneNumber是你的字符串的電話號碼..

NSString *deviceName = [UIDevice currentDevice].model;  
    if([deviceName isEqualToString:@"iPhone"]) 
    { 
     NSString *strDialedNumber = [pPhoneNumber stringByReplacingOccurrencesOfString:@" " withString:@""];  
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",strDialedNumber]]]; 
    } 
+0

感謝..... u能PLZ解釋一下是怎麼回事... – Icoder

+0

可以U PLZ解釋上面的代碼.. – Icoder

+0

iCoder,解釋:首先,他正在檢查代碼是否在iPhone上運行。因爲ipad和ipod沒有通話功能。然後,他將刪除電話號碼中的多餘空格(如果有),然後他正在撥打電話。希望這是明確的 – Satyam

0
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://9016098909891"]]; 
+0

我認爲這兩個Urs和我會採取同樣的行動 – Icoder

+0

我得到了答案從http://stackoverflow.com/questions/3574291/call-safari-in-iphone-program/3574366#3574366 – PJR

2

如果您運行的代碼,iOS版將撥出電話到指定的電話號碼。 iOS使用其原生電話應用程序來撥打電話。

請注意,電話號碼中不應有特殊字符。它應該只包含數字數字。

看看Reference from Apple

+0

無論設備是使用任何特殊的協議或其他itz啓動itz自己撥號.. – Icoder

+0

它使用自己的電話應用程序。看到我更新的答案。 – EmptyStack

2

試試這個: -

NSString *telephoneString=[self.phone stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 

     NSMutableString *str1=[[NSMutableString alloc] initWithString:telephoneString]; 
     [str1 setString:[str1 stringByReplacingOccurrencesOfString:@"(" withString:@""]]; 
     [str1 setString:[str1 stringByReplacingOccurrencesOfString:@")" withString:@""]]; 
     [str1 setString:[str1 stringByReplacingOccurrencesOfString:@"-" withString:@""]]; 
     [str1 setString:[str1 stringByReplacingOccurrencesOfString:@" " withString:@""]]; 
     telephoneString = [@"tel://" stringByAppendingString:str1]; 
     [str1 release]; 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telephoneString]]; 
+0

感謝您的代碼 – Icoder

+1

當呼叫處於暫停或忙碌狀態時,是否有任何可能向用戶發送自動圖文消息(類似於呼叫等待) – Icoder