我正在尝试将以下 NSString api 调用转换为 NSURL 对象:
http://beta.com/api/token= “69439028”
这是我设置的对象。我用反斜杠转义了引号:
NSString *theTry=@"http://beta.com/api/token=\"69439028\"";
NSLog(@"theTry=%@",theTry);
NSMutableURLRequest *url = [[NSURL alloc] URLWithString:theTry];
NSLog(@"url=%@",url);
每次我运行这个,我都会收到这个错误:
2010-07-28 12:46:09.668 RF[10980:207] -[NSURL URLWithString:]: unrecognized selector sent to instance 0x5c53fc0
2010-07-28 12:46:09.737 RF[10980:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL URLWithString:]: unrecognized selector sent to instance 0x5c53fc0'
谁能告诉我如何正确地将此字符串转换为 NSURL?
最佳答案
您正在声明一个 NSMutableURLRequest 类型的变量并使用 NSURL 初始化函数(某种程度上)。
NSMutableURLRequest *url = [[NSURL alloc] URLWithString:theTry];
尝试
NSURL *url = [[NSURL alloc] initWithString:theTry];
请注意,我已经有一段时间没有进行任何 iPhone 开发,但我认为这看起来非常准确。
关于iPhone 将 NSString 转换为 NSURL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3356852/