我有一个iOS应用程序,它有一个sqlite数据库,我正在尝试实现共享扩展。因此,我有主应用程序共享此DB以及共享扩展。
以下是我的实施
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *AppGroupId = @"XXXX";
NSURL *groupContainerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:AppGroupId];
NSString *sharedDirectory = [groupContainerURL path];
sqliteDb = [sharedDirectory stringByAppendingPathComponent:@"MYDB.sqlite"];
success = [fileManager fileExistsAtPath:sqliteDb];
NSLog(@"path : %@", sqliteDb);
如果我把我的数据库放在NSDocument目录中(没有实现共享扩展),一切正常。
但是,如果我将其移至共享目录并实施共享扩展,则应用程序在进入后台时会开始崩溃。
以下是日志,遗憾的是我无法调试为什么会发生这种情况。任何帮助都会得到真正的赞赏
崩溃日志的时间差异很大 喜欢以下
libsystem_kernel.dylib`mach_msg_trap: 0x31ae8504< + 0>:mov r12,sp 0x31ae8508< + 4>:推{r4,r5,r6,r8} 0x31ae850c< + 8>:ldm r12,{r4,r5,r6} 0x31ae8510< + 12>:mvn r12,#30 0x31ae8514< + 16>:svc#0x80 - > 0x31ae8518< + 20>:pop {r4,r5,r6,r8} 0x31ae851c< + 24>:bx lr
Foundation`- [NSConcreteMapTable dealloc]: 0x245b6f68< + 0>:推{r4,r5,r6,r7,lr} 0x245b6f6a< + 2>:添加r7,sp,#0xc 0x245b6f6c< + 4>:push.w {r8,r10} 0x245b6f70< + 8>:sub sp,#0x8 0x245b6f72< + 10>:mov r4,r0 0x245b6f74< + 12>:movw r0,#0xa10 0x245b6f78< + 16>:movt r0,#0xd9f 0x245b6f7c< + 20>:movw r1,#0xa0e 0x245b6f80< + 24>:添加r0,pc 0x245b6f82< + 26>:movt r1,#0xd9f 0x245b6f86< + 30>:添加r1,pc 0x245b6f88< + 32>:ldr.w r8,[r0] 0x245b6f8c< + 36>:ldr r5,[r1] 0x245b6f8e< + 38>:ldr.w r10,[r4,r8] 0x245b6f92< + 42>:添加r6,r4,r5 0x245b6f94< + 44>:mov r0,r6 0x245b6f96< + 46>:mov r1,r10 0x245b6f98< + 48>:bl 0x24644e10;空 0x245b6f9c< + 52>:ldr r0,[r4,r5] 0x245b6f9e< + 54>:mov r1,r10 0x245b6fa0< + 56>:ldr r2,[r6,#0x30] 0x245b6fa2< + 58>:blx r2 0x245b6fa4< + 60>:movw r0,#0x9e4 0x245b6fa8< + 64>:mov.w r10,#0x0 0x245b6fac< + 68>:movt r0,#0xd9f 0x245b6fb0< + 72>:str.w r10,[r4,r5] 0x245b6fb4< + 76>:添加r0,pc 0x245b6fb6< + 78>:ldr.w r8,[r4,r8] 0x245b6fba< + 82>:ldr r5,[r0] 0x245b6fbc< + 84>:添加r6,r4,r5 0x245b6fbe< + 86>:mov r1,r8 0x245b6fc0< + 88>:mov r0,r6 0x245b6fc2< + 90>:bl 0x24644e10;空 - > 0x245b6fc6< + 94>:ldr r0,[r4,r5]
等
答案 0 :(得分:0)
NSString * const DataBaseName = @"MYDB.sqlite";
-(BOOL) createDataBase
{
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:DataBaseName];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success) return success;
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:DataBaseName];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!!!" message:@"Failed to create writable database..." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert show];
}
return success;
}