hi friend i am passing tokenid throw this class to this here is my code how i am passing it wrong for
-(void)check
{
//app.journeyList = [[NSMutableArray alloc]init];
[self createEditableCopyOfDatabaseIfNeeded];
NSString *filePath = [self getWritableDBPath];
sqlite3 *database;
if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "SELECT Username,Password FROM UserInformation where Username=? and Password=?";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
sqlite3_bind_text(compiledStatement, 1, [txtUserName.text UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 2, [txtPassword.text UTF8String], -1, SQLITE_TRANSIENT);
//NSString *loginname= [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
// NSString *loginPassword = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
}
if(sqlite3_step(compiledStatement) != SQLITE_ROW ) {
NSLog( @"Save Error: %s", sqlite3_errmsg(database) );
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"UIAlertView" message:@"User is not valid" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
alert = nil;
//We have no data in database so send request to webserver.
//apitest = [[UIApplication sharedApplication]delegate];
//if (apitest.internetConnectionStatus != NotReachable)
// {
// [self sendRequest];
// }
}
else {
isUserValid = YES;
if (isUserValid) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"UIAlertView" message:@"Valid User" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
-(IBAction)update:(id)sender
{
test1 *check = [[test1 alloc]initWithNibName:@"test1" bundle:nil];
check.tokenapi1=tokenapi;;
[self presentModalViewController:check animated:YES];
//[self getStudents];
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *loginStatus = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",loginStatus);
//this is to perfrom insert opertion on the userinformation table
NSString *json_string = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
NSDictionary *result = [json_string JSONValue];
tokenapi = [result objectForKey:@"TokenID"];
NSLog(@"this is token id:%@",tokenapi);
//
BOOL errortest = [[result objectForKey:@"isError"] boolValue];
if(errortest == FALSE)
{
values = [result objectForKey:@"Result"];
NSLog(@"Valid User");
}
else
{
NSLog(@"Invalid User");
}
NSMutableArray *results = [[NSMutableArray alloc] init];
for (int index = 0; index<[values count]; index++) {
NSMutableDictionary * value = [values objectAtIndex:index];
Result * result = [[Result alloc] init];
result.UserID = [value objectForKey:@"UserId"];
result.FirstName = [value objectForKey:@"FirstName"];
result.LastName =[value objectForKey:@"LastName"];
result.Email =[value objectForKey:@"Email"];
result.ProfileImage =[value objectForKey:@"ProfileImage"];
result.ThumbnailImage =[value objectForKey:@"ThumbnailImage"];
result.DeviceInfoId =[value objectForKey:@"DeviceInfoId"];
NSLog(@"%@",result.UserID);
ID=result.UserID;
NSLog(@"%@",ID);
[results addObject:result];
[result release];
}
for (int index = 0; index<[results count]; index++) {
Result * result = [results objectAtIndex:index];
//save the object variables to database here
[self createEditableCopyOfDatabaseIfNeeded];
NSString *filePath = [self getWritableDBPath];
sqlite3 *database;
//NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
// NSNumber *timeStampObj = [NSNumber numberWithInt: timeStamp];
// NSLog(@"%@",timeStampObj);
// NSString *journeyid = [NSString stringWithFormat:@"%@_%@_%@", result.UserID, result.DeviceInfoId, timeStampObj];
if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "insert into UserInformation(UserID,DeviceId,Username,Password,FirstName,Email) VALUES (?,?,?,?,?,?)";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
//sqlite3_bind_text( compiledStatement, 1, [journeyid UTF8String],-1,SQLITE_TRANSIENT);
sqlite3_bind_text( compiledStatement, 1, [result.UserID UTF8String],-1,SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 2, [result.DeviceInfoId UTF8String],-1,SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 3, [txtUserName.text UTF8String],-1,SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 4, [txtPassword.text UTF8String],-1,SQLITE_TRANSIENT);
sqlite3_bind_text (compiledStatement, 5, [result.FirstName UTF8String],-1,SQLITE_TRANSIENT);
sqlite3_bind_text (compiledStatement, 6, [result.Email UTF8String],-1,SQLITE_TRANSIENT);
}
if(sqlite3_step(compiledStatement) != SQLITE_DONE ) {
NSLog( @"Save Error: %s", sqlite3_errmsg(database) );
}
else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"UIAlertView" message:@"Record added" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
alert = nil;
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
[loginStatus release];
[connection release];
[webData release];
}
-(IBAction)click:(id)sender
{
[self sendRequest];
//this is to select username and password from database.
[self check];
}
this where i am passing then token id using for updat userprofile with tokinid but it not taken here it show error in console it show tokenid invalid i thing i have to pass user id also for update vale as refrence for tokenid
答案 0 :(得分:0)
您应该使用Delegate模式将值从一个类传递给其他类。
见下文SO帖子。
How do I set up a simple delegate to communicate between two view controllers?