Paul Warkentin
Paul Warkentin

Reputation: 3899

Convert Core Data to NSString

I want to create a backup function in my app iCollege (App Store). The data should be sended via email to any email address. I'm able to send it as attachement but I want to send it as a link. Is it possible? I tried to load the Core Data file in NSData and then to NSString but it doesn't work.
I don't if it's important but I use a persistent store with the storage type NSBinaryStoreType.

Is it possible? And how can I do this?

EDIT: Ok. I try it with the attachement. First I registered a file type but in the email the file is shown with a questionmark and I'm not able to open it. I attache my file like this:

NSData *archievedData = [NSKeyedArchiver archivedDataWithRootObject:[NSString stringWithContentsOfFile:path encoding:NSISOLatin1StringEncoding error:nil]];
[mailViewController addAttachmentData:archievedData mimeType:@"application/icollege" fileName:@"iCollege.ccd"];    

This is my Info.plist:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>application/icollege</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>iCollege Backup Document</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.fischer.ccd</string>
        </array>
    </dict>
</array>
...
<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>iCollege Backup Document</string>
        <key>UTTypeIdentifier</key>
        <string>com.fischer.iCollege</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>ccd</string>
            </array>
            <key>public.mime-type</key>
            <string>application/icollege</string>
        </dict>
    </dict>
</array>

Upvotes: 0

Views: 304

Answers (1)

TechZen
TechZen

Reputation: 64428

You can't create a link that refers to a specific instance of an app on a specific device unless the app is running an http server. Even then, it would only work on a local network.

If you just want to back up the file, your best bet would to just send the persistent store file itself as an attachment. Later you can load the file back to the app and reopen it. If you want to preserve the data in a human readable format, you should attach a method to your managed object subclasses for you entities that will generate a human readable text description of each object. You can also customize that text format as needed to make it meaningful for the user.

However, for backup, you should rely on the user syncing the app. Most apps don't provide any customized backup feature and the user probably won't even think to look for one if they lose data.

Upvotes: 1

Related Questions