Reputation: 1610
I have one application in that i created the sqlite database and store in the document directory. Now i open other application from existing application and in that i want to access the existing database path. how can i do this can any one help me. I write the code below for open another application and calling the document directory. But it gets the the wrong document directory path.
==============
UIApplication *ourApplication = [UIApplication sharedApplication];
NSString *ourPath = @"POSRetail://";
NSURL *ourURL = [NSURL URLWithString:ourPath];
if ([ourApplication canOpenURL:ourURL])
{
databasePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(@"databasePath : %@",databasePath);
NSString *filePath = [databasePath stringByAppendingPathComponent:@"testapp.sqlite"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
if(fileExists)
{
NSMutableString *strRecord =[[NSMutableString alloc]init];
//Retrieve the values of database
const char *dbpath = [filePath UTF8String];
if (sqlite3_open(dbpath, &sdatabase) == SQLITE_OK)
{
// NSString *querySQL = [NSString stringWithFormat:@"SELECT * FROM employee"];
// const char *query_stmt = [querySQL UTF8String];
const char *query_stmt = "Select * from info";
sqlite3_stmt *statement;
//const char *query_stmt = "Select * from sqlite_master where type='table'";
NSMutableArray *arrTemp = [[NSMutableArray alloc] init];
if(sqlite3_prepare_v2(sdatabase, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
while (sqlite3_step(statement)==SQLITE_ROW) {
[arrTemp addObject:[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 0)]];
[strRecord appendFormat:@"%@,",[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 0)]];
[arrTemp addObject:[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 1)]];
[strRecord appendFormat:@" %@,",[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 1)]];
[arrTemp addObject:[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 2)]];
[strRecord appendFormat:@" %@,",[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 2)]];
[arrTemp addObject:[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 3)]];
[strRecord appendFormat:@" %@\n",[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 3)]];
}
NSLog(@"arrTemp : %@",arrTemp);
sqlite3_finalize(statement);
}
else
{
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(sdatabase));
}
sqlite3_close(sdatabase);
}
else
{
sqlite3_close(sdatabase);
NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(sdatabase));
}
}
else
{
NSLog(@"SQLITE DATABASE NOT AVAILABLE");
}
}
else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Receiver Not Found" message:@"The Receiver App is not installed. It must be installed." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
Upvotes: 0
Views: 130
Reputation: 7373
As if you want to access other iOS App
data then Two Words From Apple
Not Possible
As iOS
App is work in SandBox Environment
sharing data between applications so sharing data directly through the file system
is not possible, But there is also certain ways provided for sharing data review this like
iOS programming
guide now has a section on passing data between
apps by having one app claim a certain URL prefix
and then having
other apps reference that URL
. For this point of your you can look
this Apple Documentation. And Good Thread on SO
related
this Question.UIDocumentInteractionController
NOTE : No Idea With Jail Break iOS
Device I Got the Reference This Great Document.
Upvotes: 3
Reputation: 879
You can jailbreak your devices, then use some jailbreak development library that can give you each application's sandbox folder, or you can iterate the Application folder yourself.
Upvotes: 0
Reputation: 107131
Currently there is no way to access the data of another application directly. Because each application is running on a sandbox environment.
But you can do it, how ?
You need to use iCloud
. You can share the data stored the iCloud between apps, so store your database file in iCloud.
References:
You can find a tutorial on iCloud here : iCloud Programming
I cloud Data sharing is described here : iCloud Data Sharing
Upvotes: 2
Reputation: 5113
I don't think that's possible at all, each app runs in its own VM, its impossible for other apps to access data of each other, unless the data is written on a shared space like SD card itself.
Upvotes: 0