0

I am using UIImagePickerControllerDelegate in iOS for image pickup from gallery or form camera it is working fine in real device in iphone but can i use this thing in simulator so that i can see image store in sqlite DB file. This is my code for storing image in sqlite :

 NSString *docsDir;
NSArray *dirPaths;
NSString *dbPath;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
dbPath = [[NSString alloc]initWithString:[docsDir stringByAppendingPathComponent:@"clientId.db"]];
sqlite3_stmt *compiledStmt;
sqlite3 *db;
if(sqlite3_open([dbPath UTF8String], &db)==SQLITE_OK){
    NSString *insertSQL=@"insert into MESSAGE(MESSAGE,SEENTO) VALUES(?,'visitor')";
    if(sqlite3_prepare_v2(db,[insertSQL cStringUsingEncoding:NSUTF8StringEncoding], -1, &compiledStmt, NULL) == SQLITE_OK){
        //            UIImage *image = [UIImage imageNamed:@"prem.png"];
        UIImage *image = chosenImage;

        NSData *imageData=UIImagePNGRepresentation(image);

        sqlite3_bind_blob(compiledStmt, 1, [imageData bytes], [imageData length], SQLITE_TRANSIENT);

        if(sqlite3_step(compiledStmt) != SQLITE_DONE ) {
            NSLog( @"Error: %s", sqlite3_errmsg(db) );
        } else {
            NSLog( @"Insert into row id = %lld", (sqlite3_last_insert_rowid(db)));
        }

        sqlite3_finalize(compiledStmt);
    }
}
sqlite3_close(db);

the only thing is i want to pick image from simulator, so that i can extract db file and see what values are store in sqlite.db file.Is there any way to pick image form simulator or else can show sqlite.db file form real iphone device.

prem
  • 19
  • 2

1 Answers1

1

Solution 1 - For simulator, you can set the source type as photoLibrary or savedPhotosAlbum,

https://developer.apple.com/reference/uikit/uiimagepickercontroller

You then need to locate the simulator documents directory folder, and find the sqlite file there.

Solution 2.1 - Enable the itunes sharing and view the sqlite file via itunes-> device -> scroll to bottom-> click your app-> locate and download the sqlite file. To enable itunes sharing follow this - http://stackoverflow.com/a/6029954/4549304

Solution 2.2 - Access it directly from xcode, follow this link

http://help.apple.com/xcode/mac/8.0/#/dev816c242e1

Saurabh Yadav
  • 957
  • 10
  • 20
  • Thanks @SaurabhYadav it doesn't work for me but i get the solution.fro using gallery image selector in simulator we have to some key value in plist file this is what we have to add: NSPhotoLibraryUsageDescription $(PRODUCT_NAME) uses photos it work from me now I can select image form gallery in simulator. – prem Mar 01 '17 at 06:05
  • @prem You told this in the question `I am using UIImagePickerControllerDelegate in iOS for image pickup from gallery or form camera it is working fine in real device in iphone` , How come you were able to access it from the device from the gallery, if you had not added the key in info.plist already? – Saurabh Yadav Mar 01 '17 at 07:23
  • it work in real device without adding ket in info.plist but not in simulator ,after adding key in info.plist it worked in simulator also. – prem Mar 01 '17 at 09:44
  • You may not have been accessing the library in that case, if you try to access the library in the real device too, without adding the key, then it will crash. – Saurabh Yadav Mar 01 '17 at 09:50