Distribute Sqlite file with app

My app has gotten rejected for the fourth time and I’m no closer to solving this than after the first rejection. The issue seems to be happening in the Open event and the only thing it does is copy an Sqlite DB from the resources folder to the Documents folder. I talked to an app supervisor the other day on the phone and he installed the app on his device and it crashed before it even displayed the first screen. Consequently, that has to be the open event of the app because that is the only thing that runs before the first screen.

I have run this app on numerous devices as well as the simulator without any issues. What I’m looking for is code to copy the database from the resources folder to the documents folder (from someone who is doing this on their app) so that I can compare it to what I’m doing.

I’d be happy to provide someone with a copy of the app if they’d like to help resolve this issue. Very frustrating!

Could the fact that I declared my folderitems like this

dim f as folderitem

instead of like this

dim f as xojo.io.folderitem

be the issue here?

I also used the OS X syntax for special folders. Problem?

Did you get a crash log from the app supervisor?

In an iOS project using just FolderItem is equivalent to Xojo.IO.FolderItem.

You really need to get a crashlog.

I’ve got a crash log, but can’t make heads or tales out of it. Here is the pertinent part of it, I think.

Incident Identifier: 732AFE3C-7697-4645-8369-64ECDDE05FE6
CrashReporter Key: 97b7948f0d6ba204cbe200e0331133cb0d3fe7a7
Hardware Model: xxx
Process: ACAIR [392]
Path: /private/var/mobile/Containers/Bundle/Application/313907D9-AE1A-4BF1-9001-4BF1E06AE6A3/ACAIR.app/ACAIR
Identifier: com.proware-cpa.acair
Version: 1.0.4 (1.0.4)
Code Type: ARM-64 (Native)
Parent Process: launchd [1]

Date/Time: 2015-08-27 18:38:02.807 -0700
Launch Time: 2015-08-27 18:38:02.709 -0700
OS Version: iOS 8.4.1 (12H321)
Report Version: 105

Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 0

Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x000000019688f270 0x196874000 + 111216
1 libsystem_pthread.dylib 0x000000019692d15c 0x196928000 + 20828
2 libsystem_c.dylib 0x0000000196806a9c 0x1967a4000 + 404124
3 libsystem_c.dylib 0x00000001967db9c0 0x1967a4000 + 227776
4 ACAIR 0x00000001002649fc 0x1000d8000 + 1624572
5 ACAIR 0x0000000100264d94 0x1000d8000 + 1625492
6 UIKit 0x0000000188feaf74 0x188f68000 + 536436
7 UIKit 0x0000000189202650 0x188f68000 + 2729552
8 UIKit 0x0000000189205004 0x188f68000 + 2740228
9 UIKit 0x0000000189203574 0x188f68000 + 2733428
10 FrontBoardServices 0x000000018cc0d3c4 0x18cbf4000 + 103364
11 CoreFoundation 0x00000001844b3fc4 0x1843d4000 + 917444
12 CoreFoundation 0x00000001844b30cc 0x1843d4000 + 913612
13 CoreFoundation 0x00000001844b16f0 0x1843d4000 + 906992
14 CoreFoundation 0x00000001843dcf70 0x1843d4000 + 36720
15 UIKit 0x0000000188fe4220 0x188f68000 + 508448
16 UIKit 0x0000000188fded90 0x188f68000 + 486800
17 ACAIR 0x0000000100265448 0x1000d8000 + 1627208
18 ACAIR 0x00000001000e0740 0x1000d8000 + 34624
19 ACAIR 0x00000001000dcfb8 0x1000d8000 + 20408
20 ACAIR 0x00000001000dca40 0x1000d8000 + 19008
21 libdyld.dylib 0x0000000196776a04 0x196774000 + 10756

Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0 libsystem_kernel.dylib 0x0000000196874c24 0x196874000 + 3108
1 libdispatch.dylib 0x0000000196759e6c 0x196748000 + 73324
2 libdispatch.dylib 0x000000019674b998 0x196748000 + 14744

Thread 2:
0 libsystem_kernel.dylib 0x000000019688fc78 0x196874000 + 113784
1 libsystem_pthread.dylib 0x00000001969292c8 0x196928000 + 4808
2 libsystem_pthread.dylib 0x0000000196928edc 0x196928000 + 3804

Thread 3:
0 libsystem_kernel.dylib 0x000000019688fc78 0x196874000 + 113784
1 libsystem_pthread.dylib 0x00000001969292c8 0x196928000 + 4808
2 libsystem_pthread.dylib 0x0000000196928edc 0x196928000 + 3804

Thread 4 name: Dispatch queue: FBSSerialQueue
Thread 4:
0 libsystem_kernel.dylib 0x0000000196874e48 0x196874000 + 3656
1 libdispatch.dylib 0x0000000196757f3c 0x196748000 + 65340
2 FrontBoardServices 0x000000018cc0d384 0x18cbf4000 + 103300
3 libdispatch.dylib 0x0000000196749990 0x196748000 + 6544
4 libdispatch.dylib 0x0000000196749950 0x196748000 + 6480
5 libdispatch.dylib 0x00000001967540a0 0x196748000 + 49312
6 libdispatch.dylib 0x000000019674ca58 0x196748000 + 19032
7 libdispatch.dylib 0x0000000196756314 0x196748000 + 58132
8 libdispatch.dylib 0x0000000196757c48 0x196748000 + 64584
9 libsystem_pthread.dylib 0x0000000196929218 0x196928000 + 4632
10 libsystem_pthread.dylib 0x0000000196928edc 0x196928000 + 3804

Thread 5:
0 libsystem_kernel.dylib 0x000000019688fc78 0x196874000 + 113784
1 libsystem_pthread.dylib 0x00000001969292c8 0x196928000 + 4808
2 libsystem_pthread.dylib 0x0000000196928edc 0x196928000 + 3804

Thread 0 crashed with ARM Thread State (64-bit):
x0: 0x0000000000000000 x1: 0x0000000000000000 x2: 0x0000000000000000 x3: 0x0000000000000000
x4: 0x0000000000000000 x5: 0x0000000000000010 x6: 0x000000014ee09870 x7: 0x0000000000000211
x8: 0x0000000008000000 x9: 0x0000000004000000 x10: 0x000000000000000a x11: 0x0000000000000000
x12: 0x0000000000000039 x13: 0x0000000000037968 x14: 0x0000000000000015 x15: 0x0000000000000000
x16: 0x0000000000000148 x17: 0x0000000000000000 x18: 0x0000000000000000 x19: 0x0000000000000006
x20: 0x000000019a85a310 x21: 0x0000000174068f40 x22: 0x00000001002cfdf8 x23: 0x00000001002cfe18
x24: 0x00000001741e39c0 x25: 0x00000001741e39c0 x26: 0x0000000189755810 x27: 0x00000000000000b0
x28: 0x000000014ef01780 fp: 0x000000016fd26290 lr: 0x000000019692d160
sp: 0x000000016fd26270 pc: 0x000000019688f270 cpsr: 0x00000000

Have you tried symbolicating it?

Yes, but that app “Crashsymbolicator” crashes overtime I try to use it so I don’t get any info. Jason King’s app does not work for me.

And you’re putting the crashlog, .app and .dsym files into the same folder before dragging them onto the CrashSymbolicator app?

Yep. Crashes every time. I exchanged emails with Jason and he was able to run it but I never could. I get an IO exception.

If you can reproduce the issue on your own phone, you can connect your phone to Xcode, view the device log and Xcode has an option to symbolicate the crashlog. I’ve used this myself and it’s convenient. But as you’ve said you can’t reproduce the issue then that likely won’t help. Have you got access to another device, one that has never had your app on it?

I’ve installed the app on a half dozen devices - other people’s iPhones in the office - and no one has experienced a crash.

I’ve got an iPad touch at home that I can install it on that has never had the app on it. I’ll try that tonight.

I re-wrote my “open event” code that simply copies the Sqlite database that I am distributing with my application from the resources folder to the documents folder. Tested it and it runs perfectly in the simulator.

Since the app has been rejected 4 times because it crashes before it even gets to my splash screen, the only code that runs prior to that is the open event code… hence, I figured I might as well re-write it and see what happens. The crash logs provide no clue as to what’s causing the crash.

I also tried the following, with no luck. Since the IPA file is just a zip file, I decided to extract the app file from it and tried to copy it to my iPhone 6 and I got an error saying that it is not provisioned for my iPhone. Why would the app allow me to copy it, but the app in the IPA can’t be copied to it? Not sure this is related to the crashes, but just thought I’d ask. Here is the new open event code:

  '-----------------------------------------------------------------------------------------------------
  '---  COPY DB FROM RESOURCES TO DOCS FOLDER
  '-----------------------------------------------------------------------------------------------------
  
  '---  CREATE FOLDERITEM POINTING TO DB IN RECOURCES FOLDER
  dim f_ResourcesFile As FolderItem
  f_ResourcesFile = SpecialFolder.GetResource("ACAIR.dat")
  
  '---  CREATE FOLDERITEM WHERE THE DB WILL BE COPIED
  dim f_TargetLocation As FolderItem
  f_TargetLocation = SpecialFolder.Documents.Child("ACAIR.dat")
  
  if not f_TargetLocation.Exists then
    f_ResourcesFile.CopyTo(f_TargetLocation)
  end
  
  if f_TargetLocation.Exists then
    
    dim db As New SQLiteDatabase
    db.DatabaseFile = f_TargetLocation
    
    if db.Connect then
      
      rs = db.SQLSelect("Select * from ACA")
      
    end
  end

Seems to work fine. I also noticed that IOS seems to be case sensitive, because when I entered the name of the file located in the resources of the app as ACAIR.DAT it didn’t find it and generated an error. The file actually has a lowercase extension. When I changed it in the code above to lowercase, it found the file properly. Is this normal behavior?

Anyone see anything wrong with this code. By the way, there is other code elsewhere to make sure the recordset is populated.

I had a similar issue and my solution was to change the order of the Build Settings.
iOS

  • Build
  • CopyDB
  • Sign

The sign Step has to be at the end of the settings.
Hope this helps.

Interesting, that’s the first time I’ve heard that information and mine was

Build
Sign
CopyDB

I changed it and will upload to app store to see what happens.

Thanks for the tip.

This Tip was from Hal Gumbert who saved my life with it ;-))

If it works, I’ll let Hal know. Thanks again for passing it on.

Freaking awesome. After struggling with this for weeks, it was as simple as changing the order of the build steps.

WHY HAVE I NOT SEEN THIS BEFORE??? AND WHY DOESN’T MORE PEOPLE KNOW ABOUT THIS???

I agree, why is this not documented by xojo?

This was documented on the Copying Files to Device page, but I’ve made it more prominent and also added it to the Submitting to the App Store page.