ios - 如何将 NSData/除图像/URL 之外的任何信息传递到 iOS8 中的 Action Extensions

标签 ios objective-c cocoa-touch ios8

假设我有一个名为 Employee 的类

@interface Employee : NSObject

@property(nonatomic,strong) NSString *empImageURL;
@property(nonatomic,strong) NSString *empName;
@property(nonatomic,strong) NSString *empDOB;
@property(nonatomic,strong) NSString *empJobTitle;

@end

通过在 plist 中使用 maxcount 指定类型,我可以将图像/URL/字符串传递给 UIActivityViewController 类。

如何将 Employee 对象的实例传递给自定义操作扩展?

最佳答案

使用 NSCoding 将员工编码为 NSData 并发送。您必须实现 initWithCoderencodeWithCoder

-(id)initWithCoder:(NSCoder*)coder {
    if((self = [super init])) {
        _empImageURL = [coder decodeObjectForKey:@"empImageURL"];
        ...
    }
    return self;
}

-(void)encodeWithCoder:(NSCoder*)coder {
    [coder encodeObject:_empImageURL forKey:@"empImageURL"];
    ...
}

编码为数据:

data = [NSKeyedArchiver archivedDataWithRootObject:employee];

解码数据:

employee = [NSKeyedUnarchiver unarchiveObjectWithData:data];

有关使用 NSCoding 的更多详细信息,您可以查看此 tutorial .

或者 Apple Archiving guides

关于ios - 如何将 NSData/除图像/URL 之外的任何信息传递到 iOS8 中的 Action Extensions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24645979/

相关文章:

ios - 如何隐藏多个按钮是按钮数组?

iphone - 计算数据并在不同线程中绘制时崩溃。

IOS - 触摸 UIPickerView 时关闭键盘

objective-c - 如何在 iPad 的 Objective C 中解析 PDF

ios - 第一个函数执行完成后如何调用第二个函数?

ios - 如何在 Google Drive 中获取 My Drive 的子文件夹

ios - 如何为 uiwebview 的缩小设置动画?

iOS 9 启动画面是黑色的

ios - UIActivityViewController 和 UIDocumentInteractionController 不显示选项

iphone - 获取某个 UITableViewCell 的屏幕坐标?