0
 NSString *phoneStr = @"tel:";
 phoneStr = [phoneStr stringByAppendingFormat:@"%@" , self.ContactPhone];
 NSURL * phoneURL = [NSURL URLWithString:phoneStr];
 [[UIApplication sharedApplication] openURL:phoneURL]; 

このコードは機能せず、電話アプリケーションを開きません。phoneURL の値を出力すると、常に null になります

なぜこれが起こるのですか?

どうも

4

4 に答える 4

3

電話の文字列をエスケープする必要があります。

[NSURL URLWithString:[phoneStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
于 2012-07-18T12:56:10.097 に答える
1

あなたは電話の後に//を逃しました:

NSString *phoneStr = @"tel://";
 phoneStr = [phoneStr stringByAppendingFormat:@"%@" , self.ContactPhone];
 NSURL * phoneURL = [NSURL URLWithString:phoneStr];
 [[UIApplication sharedApplication] openURL:phoneURL];
于 2012-07-18T12:41:36.203 に答える
0

最初に、self.ContactPhone が空でないことを確認し、@"telprompt://"を使用して戻るか、通話終了後にアプリを再起動します。

NSString *phoneStr = @"telprompt://";
if([self.ContactPhone length]>0)
{
phoneStr = [phoneStr stringByAppendingFormat:@"%@" , self.ContactPhone];
NSURL * phoneURL = [NSURL URLWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
}
于 2012-07-18T12:50:22.383 に答える