message sent to deallocated instance using Pinterest SDK

寵の児 提交于 2019-12-04 11:12:09

What I did was make a static variable that represented the Pinterest class:

//I put this outside my @implementation code at the top of my m file
static Pinterest *_pinterest = nil;

// instantiating
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    _pinterest = [[Pinterest alloc] initWithClientId:clientId];
});

I think that Pinterest assumed that everyone would use their class as a static singleton because that's probably what they do internally. To be fair, I don't foresee using multiple client ID's with a single app in most cases. I agree, though, this is a stupefying oversight on their part. They didn't even document this behavior, what were they thinking?!

My current workaround, which seems to be the least hacky of the ideas so far is this wrapper class that doesn't use ARC:

+ (void) createPinWithClientId:(NSString *)clientId
                      imageURL:(NSURL *)imageURL
                     sourceURL:(NSURL *)sourceURL
                   description:(NSString *)descriptionText {

    Pinterest *pinterest = [[Pinterest alloc] initWithClientId:clientId];
    [pinterest createPinWithImageURL:imageURL
                           sourceURL:sourceURL
                         description:descriptionText];
}

The key is to disable ARC for the class, which keeps the runtime from deallocating the clientId.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!