提交后发布数据无法获取

时间:2016-06-07 10:12:37

标签: objective-c

我正在尝试实现访客登录。在向api提交详细信息并重定向到下一页以查看详细信息数据不是来自api之后,数据正​​在保存。请告诉我问题在哪里。我附上几个代码,以便你能够理解发生了什么?

提交访客详细信息的代码

- (IBAction)guestSubmit:(id)sender {
if ([self validateBool]) {
    BOOL check=[[AppDelegate appDelegate] checkReachability];
    if (check) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),  ^{
            NSDictionary * dic=[ServiceHelper Guest:[self guestJsonString]];
            dispatch_async(dispatch_get_main_queue(),^{
                NSArray *aKey = [dic allKeys];
                NSLog(@"Akey" ,aKey);
                if ([[aKey objectAtIndex:0] isEqualToString:@"success"]) {

                    UIAlertView * alert =[[UIAlertView alloc]initWithTitle:@"Success" message:[dic valueForKey:[aKey objectAtIndex:0]] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
                    alert.tag=25;
                    [alert show];
                  ///
                     NSString * pCode=[[NSUserDefaults standardUserDefaults]valueForKey:@"postcode"];
                    if (pCode.length==0) {
                        [[NSUserDefaults standardUserDefaults]setObject:[dic valueForKey:@"fname"] forKey:@"fname"];
                        [[NSUserDefaults standardUserDefaults]setObject:[dic valueForKey:@"lname"] forKey:@"lname"];
                        [[NSUserDefaults standardUserDefaults]setObject:[dic valueForKey:@"phone"] forKey:@"phone"];
                        [[NSUserDefaults standardUserDefaults]setObject:[dic valueForKey:@"email"] forKey:@"email"];
                        CollectionViewController * CVC=[[CollectionViewController alloc]initWithNibName:@"CollectionViewController" bundle:nil];
                        [self.navigationController pushViewController:CVC animated:YES];

                    } else {
                        [[NSUserDefaults standardUserDefaults]setObject:[dic valueForKey:@"fname"] forKey:@"fname"];
                        [[NSUserDefaults standardUserDefaults]setObject:[dic valueForKey:@"lname"] forKey:@"lname"];
                        [[NSUserDefaults standardUserDefaults]setObject:[dic valueForKey:@"phone"] forKey:@"phone"];
                        [[NSUserDefaults standardUserDefaults]setObject:[dic valueForKey:@"email"] forKey:@"email"];
                        DeliveryPaymentViewController * DPVC=[[DeliveryPaymentViewController alloc]initWithNibName:@"DeliveryPaymentViewController" bundle:nil];
                        [self.navigationController pushViewController:DPVC animated:YES];
                    }



                } else {

                    UIAlertView * alert =[[UIAlertView alloc]initWithTitle:@"Error" message:[dic valueForKey:[aKey objectAtIndex:0]] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
                    [alert show];
                                       }
            });
        });
    }
}

enter image description here

数据保存在Api中。见下面的代码

   -(NSString*)guestJsonString
{
NSMutableString *jsonStringBuilder = nil;
NSString *jsonString = @"";

@try
{
    if (jsonStringBuilder == nil)
    {
        jsonStringBuilder = [[NSMutableString alloc] init];
    }

    [jsonStringBuilder appendFormat:@"{"];
    [jsonStringBuilder appendFormat:@"\"app_id\":\"%@\",",@"2"];
    [jsonStringBuilder appendFormat:@"\"request\":\"%@\",",@"guest"];
    [jsonStringBuilder appendFormat:@"\"fname\":\"%@\",",guestFname.text];
    [jsonStringBuilder appendFormat:@"\"lname\":\"%@\",",guestLname.text];
    [jsonStringBuilder appendFormat:@"\"phone\":\"%@\",",guestPhoneNo.text];
    [jsonStringBuilder appendFormat:@"\"email\":\"%@\"",guestEmail.text];
    [jsonStringBuilder appendFormat:@"}"];
    jsonString = jsonStringBuilder;
}
@catch (NSException *exception)
{
    jsonString = @"";
}
@finally
{

    [[NSUserDefaults standardUserDefaults]setObject:jsonString forKey:@"guestjsonString"];

    return jsonString;


}}

提交后没有数据。看截图

enter image description here

** ServiceHelper.m文件**

+(NSDictionary *)Guest:(NSString *)JsonString {
NSDictionary *returnResponse;
NSData *postData = [NSData dataWithBytes:[JsonString UTF8String] length:[JsonString length]];
NSString *serviceOperationUrl = [[NSString stringWithFormat:@"http://iphone.eposapi.co.uk"]stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
returnResponse=[self stringWithUrl:[NSURL URLWithString:serviceOperationUrl] postData:postData httpMethod:@"POST"];

return returnResponse;}

1 个答案:

答案 0 :(得分:0)

检查数据解析。

     NSString * pCode=[[NSUserDefaults standardUserDefaults]valueForKey:@"postcode"];
                if (pCode.length==0) {
                    [[NSUserDefaults standardUserDefaults]setObject:[dic valueForKey:@"fname"] forKey:@"fname"];
                    [[NSUserDefaults standardUserDefaults]setObject:[dic valueForKey:@"lname"] forKey:@"lname"];
                    [[NSUserDefaults standardUserDefaults]setObject:[dic valueForKey:@"phone"] forKey:@"phone"];
                    [[NSUserDefaults standardUserDefaults]setObject:[dic valueForKey:@"email"] forKey:@"email"];
                    CollectionViewController * CVC=[[CollectionViewController alloc]initWithNibName:@"CollectionViewController" bundle:nil];
                    [self.navigationController pushViewController:CVC animated:YES];

是否检索数据。我认为这是错误。