2013年1月28日星期一

iOS Making Call Using WebView with Country Code Number

      Currently My App has a problem making call with a number(say +861010010) with Country Code using WebView way.
Then I find that let the schema 'tel:' and 'tel://' has different effect when WebView load that url. I read Apple's Document and see that Apple is using the 'tel:' schema. So I changed 'tel://' to 'tel:', done~
      The following code is part of my Project, it can fix the wrong components in a mess string from ABRecordRef number value, i.e remain all the number and the prefix '+', so that the schema can be correctly.
      Hope this post can help people get the same prolem :)
      My Weibo is @洛石
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
- (void)callContact:(NSNotification *)notice
{
    if (!isMakingCall)
    {
        if ([[UIApplicationsharedApplication] canOpenURL:[NSURLURLWithString:@"tel:+861010010"]])
        {
            NSString *phoneNumber = [notice object];
            BOOL hasPlusString = [phoneNumber hasPrefix:@"+"];
            phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSetdecimalDigitCharacterSet] invertedSet]]
componentsJoinedByString:@""];//电话Url Schema里面有各种英文字符系统会不识别,所以要处理。
            if (hasPlusString)
            {
                phoneNumber = [NSStringstringWithFormat:@"+%@",phoneNumber];
            }
            NSString *tryPhoneNumber = [NSStringstringWithFormat:@"tel:%@",phoneNumber];
            if ([phoneNumber length]>0 && [[UIApplicationsharedApplication] canOpenURL:[NSURLURLWithString:tryPhoneNumber]])
            {
                isMakingCall = YES;              [selfperformSelectorOnMainThread:@selector(refreshMainTableView:) withObject:nilwaitUntilDone:YES];
                NSLog(@"callContact phoneNumber:%@",tryPhoneNumber);
                NSURL    *url = [NSURLURLWithString:tryPhoneNumber];
                if (dialWebview==nil)
                {
                    dialWebview = [[UIWebViewalloc] initWithFrame:CGRectMake(40, 373, 35, 40)];
                    // Make webview transparent
                    dialWebview.alpha = 0.0;
                    // Assume we are in a view controller and have access to self.view
                    // insert webview under call button so if user cancels the view
                    // doesn't interfere with normal button operation              [self.viewinsertSubview:dialWebviewbelowSubview:self.view];
                }
                [dialWebviewloadRequest:[NSURLRequestrequestWithURL:url]];
            }
            else
            {
                [OMGToastshowWithText:@"对不起,您拨打的不是电话号码。" duration:2];
            }
        }
        else
        {
            [OMGToastshowWithText:@"对不起,您的设备无法拨打电话。" duration:2];
        }
    }
}



------
My new business with my wife, wholesale meddle-to-high end men's seamless underwear in the Netherlands: https://ecosharelife.com