gpt4 book ai didi

ios - 服务消费时的匿名响应 iOS

转载 作者:行者123 更新时间:2023-11-29 12:16:58 24 4
gpt4 key购买 nike

我面临服务响应的匿名行为。有时服务很好,有时它会给出错误消息“找不到具有指定主机名的服务器”。我正在使用 AFNetworking。相同的服务在 android 平台上运行良好。有没有更好的方法可以在 iPhone 中准确获取它们。

这是我的一段代码:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

NSDictionary *params = @{@"email" : txtEmail.text,
@"password" : txtPassword.text,

};
AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
operationManager.requestSerializer = [AFJSONRequestSerializer serializer];
operationManager.responseSerializer = [AFJSONResponseSerializer serializer];
[operationManager POST:@"http://somelink/someuser.svc/login" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", operation.responseString);
NSDictionary *responseDict = responseObject;
NSLog(@"%@",[responseDict valueForKey:@"result_code"]);
if ([[responseDict valueForKey:@"result_code"] isEqualToString:@"1"]) {
NSDictionary *data = [responseObject objectForKey:@"result_data"];
NSLog(@"%@",[data objectForKey:@"email"]);


[[NSUserDefaults standardUserDefaults]setObject:[data objectForKey:@"user_id"] forKey:@"UserId"];
NSString *query = [NSString stringWithFormat:@"insert into userMaster (user_id, name_first, name_last, email, password, image, gender, rec_limit, total_followers, total_following, is_brand, category) values ('%@','%@','%@','%@','%@','%@','%@',%d,'%@','%@',%d,%d)",[data objectForKey:@"user_id"],[data objectForKey:@"name_first"],[data objectForKey:@"name_last"],[data objectForKey:@"email"],[data objectForKey:@"password"],[data objectForKey:@"image"],[data objectForKey:@"gender"],[[data objectForKey:@"rec_limit"]intValue],[data objectForKey:@"total_followers"],[data objectForKey:@"total_following"],[[data objectForKey:@"is_brand"]intValue],[[data objectForKey:@"category"]intValue]];

// NSLog(@"%@",[data objectForKey:@"intrests"]);


NSLog(@"%@",query);
int n = [service insertUpdateDeleteWithQuery:query inDatabase:@"WaveDb.sql"];
NSLog(@"%d",n);

NSArray *arr = [data objectForKey:@"intrests"];
for (int i = 0; i < arr.count; i++) {
NSLog(@"%@",[arr objectAtIndex:i]);

query = [NSString stringWithFormat:@"insert into userCategory (user_id, cat_id) values ('%@','%@')",[[NSUserDefaults standardUserDefaults]objectForKey:@"UserId"],[arr objectAtIndex:i]];
[service insertUpdateDeleteWithQuery:query inDatabase:[DataClass databaseName]];
}



dispatch_async(dispatch_get_main_queue(), ^{
[(AppDelegate *)[[UIApplication sharedApplication]delegate]hideProgress];
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"login"];
WallViewController *main = [self.storyboard instantiateViewControllerWithIdentifier:@"wallView"];
[self.navigationController pushViewController:main animated:YES];
});
}
else {
[(AppDelegate *)[[UIApplication sharedApplication]delegate]hideProgress];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alert!" message:@"Invalid username and password" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
}
} failure:^(AFHTTPRequestOperation operation, NSError error) {
NSLog(@"Error: %@", error);
dispatch_async(dispatch_get_main_queue(), ^{
[(AppDelegate *)[[UIApplication sharedApplication]delegate]hideProgress];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alert!" message:@"Some technical error occured. Try later." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];

});
}];



});

最佳答案

在任何代码执行解决我的问题之前检查可达性

关于ios - 服务消费时的匿名响应 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31780798/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com