2016-06-07 52 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

是的價值是不是來到這裏。但我無法調試它。 –