1

電話番号を NSUserDefaults に NSString として保存しようとしています。何らかの理由で、以下のコードが機能しません。変数を使用しない場合、コードは機能しますが、機能させることはできません。誰にも理由はありますか?

NSString *savedPhone = [[NSUserDefaults standardUserDefaults]
                        stringForKey:@"savedPhone"];

NSString *callNumber = [NSString stringWithFormat:@"%@%@",@"tel://",savedPhone];

NSURL *myURL = [NSURL URLWithString:callNumber];
[[UIApplication sharedApplication] openURL:myURL];

誰かアイデアがあれば教えてください。ありがとうございました!

4

4 に答える 4

1

URL 形式を変更する (削除//)

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:2135554321"]];
于 2013-02-01T08:15:44.587 に答える
0

以下のコードで達成できます:

NSUserDefaults *objUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *savedPhone = [objUserDefaults objectForKey:@"savedPhone"];
[self callNumber:savedPhone];

次に、以下の関数を追加します。

-(void)callNumber:(NSString *)pstrContactNo
{
    NSString *strDeviceModel = [UIDevice currentDevice].model;
    if(![strDeviceModel isEqualToString:@"iPhone"])
    {
            UIAlertView *objAlertMsg = [[UIAlertView alloc] initWithTitle:@""
                                                       message:@"Calling is not supported in this device."
                                                      delegate:nil
                                             cancelButtonTitle:@"OK"
                                             otherButtonTitles:nil];
       [objAlertMsg show];
       [objAlertMsg release];
    }
    else
    {
        pstrContactNo = [NSString stringWithFormat:@"tel:%@",pstrContactNo];
        NSString *strDialedContact = [pstrContactNo stringByReplacingOccurrencesOfString:@" " withString:@""];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strDialedContact]];
    }
}

これで問題が解決します。

乾杯!

于 2013-02-01T08:21:43.507 に答える
0
  NSString *number = YOUR-NUMBER;       
  NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",number]];

 [[UIApplication sharedApplication] openURL:url]; 

このコードを試してみてください。通話が終了した後、アプリに戻ります

于 2013-02-01T09:03:37.687 に答える
0

次のように変更しますcallNumber: NSString *callNumber = [NSString stringWithFormat:@"tel:%@",savedPhone];

于 2013-02-01T08:19:52.770 に答える