Associating sqlite3 db to an iPhone app

前端 未结 3 779
独厮守ぢ
独厮守ぢ 2020-12-30 18:06

I\'m trying to associate an SQLite3 database file with our app so that it\'s easy to open backed up database from an email. The following however does not seem to work as Ma

相关标签:
3条回答
  • 2020-12-30 18:46

    For completeness and possibly my own reference later here is a bit of the further details that got it working for me:

    Declaring Document Types your app supports (eg sqlite3 databases)

    <key>UTExportedTypeDeclarations</key>
        <array>
            <dict>
                <key>UTTypeIdentifier</key>
                <string>com.company.sqlite3.database</string>
                <key>UTTypeReferenceURL</key>
                <string>http://www.company.com/</string>
                <key>UTTypeDescription</key>
                <string>MyCompany SQLite Database</string>
                <key>UTTypeIconFile</key>
                <array>
                    <string>Icon-Small.png</string>
                    <string>Icon.png</string>
                </array>
                <key>UTTypeConformsTo</key>
                <array>
                    <string>public.database</string>
                    <string>public.data</string>
                </array>
                <key>UTTypeTagSpecification</key>
                <dict>
                    <key>public.filename-extension</key>
                    <array>
                        <string>sqlite</string>
                    </array>
                    <key>public.mime-type</key>
                    <array>
                        <string>application/x-sqlite3</string>
                        <string>application/octet-stream</string>
                    </array>
    
                </dict>
            </dict>
        </array>
    <key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeName</key>
            <string>MyCompany SQLite Database</string>
            <key>CFBundleTypeIconFiles</key>
            <array>
                <string>Icon-Small.png</string>
                <string>Icon.png</string>
            </array>
    
            <key>CFBundleTypeExtensions</key>
            <array>
                <string>sqlite</string>
            </array>
    
            <key>CFBundleTypeMIMETypes</key>
            <array>
                <string>application/x-sqlite3</string>
                <string>application/octet-stream</string>
            </array>
    
            <key>LSHandlerRank</key>
            <string>Alternate</string>
    
            <key>LSItemContentTypes</key>
            <array>
                <string>com.company.sqlite3.database</string>
            </array>
    
            <key>NSPersistentStoreTypeKey</key>
            <string>SQLite</string>
    
        </dict>
    </array>
    

    Copy paste the above XML into your Info.plist file.

    Setting the 'Store Type' to 'SQLite' didn't wasn't the killer fix for me.

    My previous post here mentioned a rather incorrect way of getting it to work which accepts all files and didn't properly export the type.

    Also if your app is emailing off these files as attachments make sure it matches the MIME type you set it to capture. The application/octet-stream is not important it is just that older versions of our app are emailing out the databases with that MIME type.

    eg,

    [controller addAttachmentData:[NSData dataWithContentsOfFile:dbPath] mimeType:@"application/x-sqlite3" fileName:filename];
    

    I sure hope anyone else that tries to find out how to get their app to support opening sqlite3 database backups finds this helpful.

    0 讨论(0)
  • 2020-12-30 18:57

    As per Apple's documentation, CFBundleDocumentTypes is an array, not a dict.

    You have:

    <key>CFBundleDocumentTypes</key>
    <dict>
    

    so the <dict> needs to be in an <array> element, like so:

    <key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeName</key>
            <string>App Database</string>
            <!-- ... -->
        </dict>
    </array>
    
    0 讨论(0)
  • 2020-12-30 18:59

    Okay I've sorted this out. If you instead use 'target's info' panel and add your document type there (and then select 'SQLite' as the type') it just works. Obviously provided you've exported the type as above.

    0 讨论(0)
提交回复
热议问题