簡體   English   中英

iOS:使用Android上的電話號碼撥打手機屏幕

[英]iOS: call mobile phone screen with phone number like on Android

當我們在應用程序中按“電話”圖標時,是否可以執行與Android上相同的操作?

在Android設備上,我們將看到“電話”屏幕,其中包含輸入的電話號碼。
在iOS上,它將立即撥打電話號碼。

例:
Android:單擊某些應用程序的呼叫按鈕->具有預輸入號碼的“本地Android電話”屏幕->手動單擊呼叫按鈕
iOS:單擊同一應用程序的呼叫按鈕->立即撥打電話號碼
我需要知道,是否可以像在Android上那樣將第二步添加到iOS中。

是的,可以通過如下方式使用openUrl來實現,我寫得很快,可以在objc中嘗試相同

//迅速

 func makePhoneCall(_ phoneNumber: String?) {
    if phoneNumber != nil && phoneNumber?.length ?? 0 > 0 {
        let charSet: CharacterSet = CharacterSet(charactersIn: "0123456789-+()").inverted
        let cleanedString: String? = (phoneNumber!.components(separatedBy: charSet) as NSArray).componentsJoined(by:"")
        let escapedPhoneNumber: NSString? = cleanedString?.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) as NSString?
        let phoneURLString: String = String(format:"telprompt:%@", escapedPhoneNumber!)
        let phoneURL: URL? = URL(string: phoneURLString)
        if phoneURL != nil {
            if UIApplication.shared.canOpenURL(phoneURL!) == true {
                UIApplication.shared.openURL(phoneURL!)
            } else {
                // show alert or something
            }
        }
    }
}

// objc

-(void) makePhoneCall:(NSString *)phoneNumber {
if(phoneNumber.length > 0) {
    NSCharacterSet *charSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet];
    NSString *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:charSet] componentsJoinedByString:@""];
    NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEncodingWithAllowedCharacters:  [NSCharacterSet URLQueryAllowedCharacterSet]];
    NSString *phoneURLString = [NSString stringWithFormat:@"telprompt:%@", escapedPhoneNumber];
    NSURL *url = [NSURL URLWithString:phoneURLString];
    if([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
    } else {
        // show alert // or something
    }

}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM