将核心数据转换为 NSString
我想在我的应用程序 iCollege (App Store)。数据应通过电子邮件发送至任何电子邮件地址。我可以将其作为附件发送,但我想将其作为链接发送。是否可以?我尝试将核心数据文件加载到 NSData 中,然后加载到 NSString 但它不起作用。
如果它很重要的话我不知道,但我使用存储类型为 NSBinaryStoreType 的持久存储。
是否可以?我怎样才能做到这一点?
编辑:好的。我用附件试试。首先,我注册了一个文件类型,但在电子邮件中该文件显示带有问号,我无法打开它。我像这样附加我的文件:
NSData *archievedData = [NSKeyedArchiver archivedDataWithRootObject:[NSString stringWithContentsOfFile:path encoding:NSISOLatin1StringEncoding error:nil]];
[mailViewController addAttachmentData:archievedData mimeType:@"application/icollege" fileName:@"iCollege.ccd"];
这是我的 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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非应用程序正在运行 http 服务器,否则您无法创建引用特定设备上应用程序的特定实例的链接。即使如此,它也只能在本地网络上运行。
如果您只想备份文件,最好的选择是将持久存储文件本身作为附件发送。稍后您可以将文件加载回应用程序并重新打开它。如果您想以人类可读的格式保存数据,您应该将一个方法附加到实体的托管对象子类中,该方法将为每个对象生成人类可读的文本描述。您还可以根据需要自定义该文本格式,使其对用户有意义。
但是,对于备份,您应该依赖用户同步应用程序。大多数应用程序不提供任何定制的备份功能,如果用户丢失数据,他们可能甚至不会想到寻找备份功能。
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.