我是 iPhone 开发新手。我正在使用 xcode 4.2。
当我点击保存按钮时,我从 html 页面获取值并且我的网络服务正在处理它们,然后我收到错误:
program received signal: EXC_BAD_ACCESS
在我的网络服务调用函数中。这是我的代码:
NSString *val=[WebviewObj stringByEvaluatingJavaScriptFromString:@"save()"];
NSLog(@"return value:: %@",val);
[adict setObject:[NSString stringWithFormat:@"%i",userid5] forKey:@"iUser_Id" ];
[adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:0] forKey:@"vImage_Url"];
[adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:1] forKey:@"IGenre_Id"];
[adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:2] forKey:@"vTrack_Name"];
[adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:3] forKey:@"vAlbum_Name"];
[adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:4] forKey:@"vMusic_Url"];
[adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:5] forKey:@"iTrack_Duration_min"];
[adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:6] forKey:@"iTrack_Duration_sec"];
[adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:7] forKey:@"vDescription"];
NSLog(@"dict==%@",[adict description]);
NSString *URL2= @"http://184.164.156.55/Music/Track.asmx/AddTrack";
obj=[[UrlController alloc]init];
obj.URL=URL2;
obj.InputParameters = adict;
[obj WebserviceCall];
obj.delegate= self;
//this is my function..it is working for so many function calls
-(void)WebserviceCall{
webData = [[NSMutableData alloc] init];
NSMutableURLRequest *urlRequest = [[ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString: URL ] ];
NSString *httpBody = @"";
for(id key in InputParameters)
{
if([httpBody length] == 0){
httpBody=[httpBody stringByAppendingFormat:@"&%@=%@",key,[InputParameters valueForKey:key]];
}
else{
httpBody=[httpBody stringByAppendingFormat:@"&%@=%@",key,[InputParameters valueForKey:key]];
}
}
httpBody = [httpBody stringByAppendingFormat:httpBody];//Here i am getting EXC_BAD_ACCESS
[urlRequest setHTTPMethod: @"POST" ];
[urlRequest setHTTPBody:[httpBody dataUsingEncoding:NSUTF8StringEncoding]];
[urlRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
}
谁能帮帮我?
提前致谢
最佳答案
stringByAppendingFormat
需要一个(sprintf 样式)格式化字符串作为它的第一个参数,然后是每个 % 格式占位符的另一个参数。例如:
[httpBody stringByAppendingFormat:@"Integer: %d, String: %@", 1234, @"Hello"];
如果您的 httpBody
字符串恰好包含一个 '%' 后跟一个有效的格式类型(例如 'd'、'f'、'@' 等),那么 stringByAppendingFormat
将需要您未提供的额外参数。尝试取消引用这些参数将导致您的 EXC_BAD_ACCESS。
我没有完全遵循您的代码逻辑,所以我不确定您在那一行的实际意图。
关于ios - 接收信号 : EXC_BAD_ACCESS in web service call function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11373958/