我有一個自定義文件UTI附件差不多在我的應用程序中工作時共享作爲消息。它將文件作爲附件嵌入消息中正確的文件類型「kitlist」,並在iPad和iPhone上接收。如果您從普通消息中點擊附件,則不會發生任何事情。但是,如果點擊右上角的信息按鈕,然後選擇附件,請點擊文件並分享此文件,應用程序將顯示爲可能的目的地。選擇它會在我的應用程序中成功打開文件。目前,選擇郵件作爲共享目的地不會導致附件出現在電子郵件中;我不知道這是否是相關的。我也嘗試使用子類UIActivityItemProvider而不是實現協議UIActivityItemSource子類NSObject,但沒有區別。對另一個iOS設備進行空中操作很好。iOS自定義附件不直接從消息中打開
這裏是我的plist的相關片段:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>KitList Transfer File Type</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>co.SM.KitListFile.kitlist</string>
</array>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>KitList Transfer File</string>
<key>UTTypeIdentifier</key>
<string>co.SM.KitListFile.kitlist</string>
<key>UTTypeSize320IconFile</key>
<string>BergenBig</string>
<key>UTTypeSize64IconFile</key>
<string>Bergen</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>kitlist</string>
</dict>
</dict>
</array>
的代碼,以使附件:
@interface SMCustomAttachmentTransfer()
@property (nonatomic, strong) NSMutableArray *images;
@end
@implementation SMCustomAttachmentTransfer
- (void)encodeWithCoder:(NSCoder *)aCoder
{
self.images = [NSMutableArray array];
[aCoder encodeObject:self.list forKey:@"list"];
[self walkTheList:[self.list valueForKey:keySubItems] withCoder:aCoder];
[aCoder encodeObject:self.images forKey:@"images"];
}
- (void)walkTheList:(NSDictionary *)items withCoder:(NSCoder *)aCoder
{
for (NSDictionary *item in items)
{
if ([item valueForKey:keyDetailImage])
{
[self.images addObject:[item valueForKey:keyDetailImage]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:[item valueForKey:keyDetailImage]];
[aCoder encodeObject:[NSData dataWithContentsOfFile:getImagePath] forKey:[item valueForKey:keyDetailImage]];
}
if ([item valueForKey:keySubItems])
{
[self walkTheList:[item valueForKey:keySubItems] withCoder:aCoder];
}
}
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self)
{
self.list = [aDecoder decodeObjectForKey:@"list"];
NSArray *images = [aDecoder decodeObjectForKey:@"images"];
for (NSString *image in images)
{
NSData *pngData = [aDecoder decodeObjectForKey:image];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
[pngData writeToFile:[documentsPath stringByAppendingPathComponent:image] atomically:YES];
}
}
return self;
}
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController
{
// must be data placeholder for attachment to be embedded in a message.
return [NSData data];
}
- (NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(NSString *)activityType
{
return [self.list valueForKey:keyName];
}
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(UIActivityType)activityType
{
return [NSKeyedArchiver archivedDataWithRootObject:self];
}
- (NSString *)activityViewController:(UIActivityViewController *)activityViewController dataTypeIdentifierForActivityType:(NSString *)activityType
{
return @"co.SM.KitListFile.kitlist";
}
你有沒有這個運氣? –
不,@JordanSmith,遺憾的是沒有。仍然在做! – Nick