0

4 つの UIButtons を備えたアプリがあり、それぞれに電話番号を事前にプログラムしたいと考えています。私はこのように書いています:

- (IBAction)callFirst:(id)sender {
[NSURL URLWithString:@"tel.0739421700"];
}

- (IBAction)callSecond:(id)sender {
[NSURL URLWithString:@"tel.0705652000"];
}

- (IBAction)callThird:(id)sender {
[NSURL URLWithString:@"tel.0705666900"];
}

- (IBAction)callFourth:(id)sender {
[NSURL URLWithString:@"tel.0702857900"];
}

シミュレーターでアプリを開くと、ログに移動してエラーが表示されます。代わりにどのように記述すればよいですか?実行するとこうなります。「return UIApplicationMain...」部分は、その端に緑色の矢印が付いています。右側には、「 Thread 1: signal sigabrt 」と表示されています。これは main.m ファイルからのものです。

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

前もって感謝します!

4

1 に答える 1

0
  1. URLを開かなかった
  2. 間違ったURL スキームを使用しました

このようなものはうまくいくはずです:

- (BOOL)callPhoneNumberWithString:(NSString *)phoneNumberString {
    NSURL *url = [NSURL URLWithString:phoneNumberString];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
        return YES;
    }
    return NO;
}

- (IBAction)callFirst:(id)sender {
    [self callPhoneNumberWithString:@"tel:0123456789"]; 
}
于 2012-11-19T20:07:23.250 に答える