2016-06-07 85 views
0

我正在尝试实现访客登录。在向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;} 
+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]; 

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

+0

是的价值是不是来到这里。但我无法调试它。 –