我正在尝试使用适用于iOS的Amazon API来处理Objective-C中的Amazon网站登录。我正在使用this source。
但是,当我实现AMZNAuthorizeUserDelegate
时,我收到以下错误消息:
ARC禁止发送'retain'的明确消息。
我之前从未使用过Objective-C,所以如果有人能帮我解决这些问题,我将不胜感激。
这是我的代码:
#import <LoginWithAmazon/LoginWithAmazon.h>
#import "AMZNAuthorizeUserDelegate.h"
#import "AMZNGetProfileDelegate.h"
@implementation AMZNAuthorizeUserDelegate
- (id)initWithParentController:(ViewController*)aViewController {
if(self = [super init]) {
parentViewController = [aViewController retain];
}
return self;
}
- (void)requestDidSucceed:(APIResult *)apiResult {
AMZNGetProfileDelegate* delegate = [[[AMZNGetProfileDelegate alloc] initWithParentController:parentViewController] autorelease];
[AIMobileLib getProfile:delegate];
}
- (void)requestDidFail:(APIError *)errorResponse {
NSString *message = errorResponse.error.message;
// Your code when the authorization fails.
[[[[UIAlertView alloc] initWithTitle:@"" message:[NSString
stringWithFormat:@"User authorization failed with message: %@",
errorResponse.error.message] delegate:nil
cancelButtonTitle:@"OK"otherButtonTitles:nil] autorelease] show];
}
@end
答案 0 :(得分:2)
错误消息正确:对retain
的调用不再有效。
Automatic Reference Counting或ARC添加到Objective-C语言中。在ARC之前,您必须通过调用-retain
,-release
和-autorelease
等方法来手动管理应用的内存使用情况。 ARC在编译时自动管理这些调用,因此,不允许您自己调用它们。
正如@ Paulw11在评论中提到的那样,你应该能够用
代替那一行parentViewController = aViewController
并且ARC将自动执行正确的操作。