Couchbase lite on the new Apple TV (tvOS)

#1

Hi,

I received the new Apple TV that allows developers to make apps on it. So I tried to make my company’s iOS app (that uses couchbase lite ios and CBLIncrementalStore) run on it.
In the simulator (same as iOS simulator), it works fine, but when I ran on the actual device, the Apple TV, the app crashes at launch.

Then I figured out that a tvOS app can’t actually write to disk (sqlite). Instead, iit needs to use CloudKit… :’(

Would it be possible to use CBLIncrementalStore in memory only ?
Thanks : -)

#2

We just received our dev kit Friday and haven’t had a chance to test with it yet.

My understanding is that apps can write to disk, but that their files may be deleted at any time after the app quits, to free up space. So I don’t think the crash is due to that. Have you looked at the backtrace?

#3

The error I have is when the Core Data Stack is set up:

2015-09-20 20:54:38.902 tivi[300:112091] ERROR : NO ERRORS Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “tivi” in the folder “Application Support”." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/9EEA69DB-380D-4DCD-B67E-C75F163EE443/Library/Application Support/tivi, NSUnderlyingError=0x1576b85c0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
#4

You must be right, I’ll try to put it in the Cashes directory

#5

Oh, interesting. Let me know how that works. (This is making me really glad we got a dev kit! I figured there’d be some issues like this. In the next release we can check for tvOS and put the default database location in Caches.)

#6

Sh**… I put the store in the Cashes directory and I have the same error :frowning:

CoreData: error: -addPersistentStoreWithType:CBLIncrementalStore configuration:(null) URL:file:///var/mobile/Containers/Data/Application/D359D3AC-8534-4504-B259-67CCA0771476/Library/Caches/tivi/couchdatabase728 options:(null) ... returned error Error Domain=CBLISErrorDomain Code=6 "Could not create database" UserInfo={NSLocalizedDescription=Could not create database} with userInfo dictionary {
    NSLocalizedDescription = "Could not create database" 

Where have you read you could write to disk ? I really want to make that work :stuck_out_tongue:
Thanks!

#7

I tried writing a file (an image) at the same filepath and it worked, so there must be something related sqlite store creation.

The error is generated when calling this method:

[coordinator migratePersistentStore:importStore toURL:incrementalStoreURL options withType:[CBLIncrementalStore type] error:&error];
#8

Well, that’s weird. You could try adding a bit of test code to try writing a file to various directories, just using simple methods like +[NSData writeToPath:].

Our dev unit arrived, so I’ll be setting it up today and hopefully trying some stuff out like the above.

#9

I made some tests: the only directory that accepts writing is the NSCachesDirectory, not the NSDocumentDirectory nor NSApplicationSupportDirectory.

#10

Cool. I’ve got my AppleTV set up and Xcode 7.1 installed, and I’m setting up the Couchbase Lite project to build for tvOS. Our of curiosity: What did you do to build a tvOS version of Couchbase Lite? I’m having to make a lot of changes — creating new targets, changing dependencies, etc. — and I wonder if you had to do all that too or if you found a simpler way to retarget that I don’t know about (:

#11

Hmmm strange. I didn’t rebuild couchbase lite actually, I took the framework as is. In my project i added -ObjC in other linker flag, I don’t know if it’s related…

Ah, I just looked again at my project and I have lots of warnings like this

warning: URGENT: building for tvOS simulator, but linking in object file (/Users/florion/Downloads/aaa/tivi/tivi/Vendor/External/CouchbaseLite.framework/CouchbaseLite(BLIPHTTPLogic.o)) built for iOS. Note: This will be an error in the future.

I didn’t really care since since was just to make a quick a dirty prototype :- )