[英]How to pass NSData/any information apart from Image/URL into Action Extensions in iOS8
Consider I have a class called Employee
考虑我有一个叫做
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
I am able to pass the image/URL/Strings to UIActivityViewController
class by specifying the type in plist with maxcount
. 我可以通过使用
maxcount
在plist中指定类型,将图像/ URL /字符串传递给UIActivityViewController
类。
How to pass the Instance of Employee object to Custom Action Extension? 如何将Employee对象的实例传递给Custom Action Extension?
Use NSCoding to encode the employee as NSData and send that. 使用NSCoding将员工编码为NSData并将其发送。 You'll have to implement
initWithCoder
and encodeWithCoder
您必须实现
initWithCoder
和encodeWithCoder
-(id)initWithCoder:(NSCoder*)coder {
if((self = [super init])) {
_empImageURL = [coder decodeObjectForKey:@"empImageURL"];
...
}
return self;
}
-(void)encodeWithCoder:(NSCoder*)coder {
[coder encodeObject:_empImageURL forKey:@"empImageURL"];
...
}
To encode as data: 编码为数据:
data = [NSKeyedArchiver archivedDataWithRootObject:employee];
To decode data: 解码数据:
employee = [NSKeyedUnarchiver unarchiveObjectWithData:data];
For more details on using NSCoding, you can see this tutorial . 有关使用NSCoding的更多详细信息,请参阅本教程 。
Or the Apple Archiving guides 或Apple归档指南
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.