简体   繁体   English

如何将NSData对象设置为PFObject?

[英]How to set a NSData object to PFObject?

I added a column location of Object type in _User class. 我在_User类中添加了Object类型的列location I'm assuming that means NSData type in iOS. 我假设这意味着iOS中的NSData类型。 Not exactly sure what's the correct way of doing this. 不完全确定执行此操作的正确方法是什么。 I'm getting an error when assigning an NSData to self.location. 将NSData分配给self.location时出现错误。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

Error Domain=Parse Code=111 "invalid type for key location, expected map, but got bytes" UserInfo=0x1740f9a00 {code=111, originalError=Error Domain=NSURLErrorDomain Code=-1011 "The operation couldn't be completed. (NSURLErrorDomain error -1011.)", temporary=0, error=invalid type for key location, expected map, but got bytes, NSLocalizedDescription=invalid type for key location, expected map, but got bytes} 错误域=解析代码= 111“关键位置的无效类型,预期的映射,但是有字节” UserInfo = 0x1740f9a00 {code = 111,originalError = Error域= NSURLErrorDomain代码= -1011“操作无法完成。(NSURLErrorDomain错误-1011。)”,临时= 0,错误=密钥位置的无效类型,预期的映射,但有字节,NSLocalizedDescription =密钥位置的无效类型,预期的映射,但有字节}

BYFUser.h BYFUser.h

#import <Parse/Parse.h>

@interface BYFUser : PFUser <PFSubclassing>

@property (nonatomic, strong) NSData *location;

@property (nonatomic, strong) CLLocation *cllocation;

@end

BYFUser.m BYFUser.m

@implementation BYFUser

@dynamic location;

+ (void)load
{
    [BYFUser registerSubclass];
}

- (void)setCllocation:(CLLocation *)cllocation
{
    if ([cllocation isKindOfClass:[CLLocation class]]) {
        self.location = [NSKeyedArchiver archivedDataWithRootObject:cllocation];
    }
}

- (CLLocation *)cllocation
{
    if ([self.location isKindOfClass:[NSData class]]) {
        return [NSKeyedUnarchiver unarchiveObjectWithData:self.location];
    }
    return nil;
}

@end

Make the column a geopoint type and access it from iOS using the PFGeoPoint class. 将列设置为geopoint类型,然后使用PFGeoPoint类从iOS访问它。 PFGeoPoint can be instantiated with a CLLocation. 可以使用CLLocation实例化PFGeoPoint。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM