Karoh
Karoh

Reputation: 2470

How do I build a native ios database using fmdb for a native trigger.IO plugin.

I'd like to use a native database for storage using a native plugin. Since Apple's base API is in pure C, I'd like to use a 3rd party library such as FBDB. Ideally, our javascript will construct the 'query' and send it over to our native plugin for handling but this isn't absolutely necessary.

  1. How do I go about importing a 3rd party library for use? What parts of the FMDB library will I want to include & how do I go about adding libsqlite3.dylib? Should FMDB target the ForgeModule and ForgeModuleResources as well? I've looked at the docs concerning this but am having difficulty applying those instructions to FMDB specifically.

  2. Can you give me a more detailed idea of what a good file structure would look like for this?

  3. Would you even recommend using FMDB, are there alternative options that would work better with trigger? Additionally, ForgeInspector does ARC correct?

Basically I'm looking for an outline to follow as well as a sqlite wrapper recommendation.

Thanks!

Upvotes: 2

Views: 759

Answers (1)

James Brady
James Brady

Reputation: 27492

  1. Including third party code to your iOS plugin is covered here: http://docs.trigger.io/en/v1.4/modules/native/external_libraries.html#ios.

    To use FMDB, you should include the repo and copy the .h and .m files into your ForgeModule project (remember to add the files to your ForgeModule target):

    add FMDB files to project

    Next, add the libsqlite3.dylib framework to both the ForgeModule target (in the ForgeModule project) and the ForgeInspector target (in the ForgeInspector project):

    add libsqlite framework

    You'll also need to disable ARC for fmdb.m (also shown above).

    After that you should be able to import the FMDB headers and use the ForgeInspector to try out your plugin.

    Note that when it comes to uploading versions of the plugins, you'll need to add an iOS build step to include the SQLite framework - see http://docs.trigger.io/en/v1.4/modules/native/native_build_steps.html#add-ios-system-framework.

  2. If your plugin is called fmdb (we'd recommend namespacing it more, to avoid conflicts), you must have fmdb_API.h and fmdb_API.m - I normally put them inside their own group, and inside their own folder. I'd also put 3rd party code in its own group and folder, e.g.:

    % find fmdb FMDB_lib
    fmdb
    fmdb/fmdb_API.h
    fmdb/fmdb_API.m
    FMDB_lib
    FMDB_lib/FMDatabase.h
    FMDB_lib/FMDatabase.m
    FMDB_lib/FMDatabaseAdditions.h
    FMDB_lib/FMDatabaseAdditions.m
    FMDB_lib/FMDatabasePool.h
    FMDB_lib/FMDatabasePool.m
    FMDB_lib/FMDatabaseQueue.h
    FMDB_lib/FMDatabaseQueue.m
    FMDB_lib/fmdb.m
    FMDB_lib/FMResultSet.h
    FMDB_lib/FMResultSet.m
    
  3. We haven't used FMDB internally, so don't have loads of experience with it. However, I do know that trying to shoe-horn C-centric APIs into Objective-C code is pretty painful (I'm thinking of AddressBook.framework). FMDB aims to solve that for SQLite, so it seems like a good idea.

Upvotes: 2

Related Questions