Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTAPIBaseManager对象的dealloc调用问题 #36

Open
TouchFriend opened this issue Sep 2, 2020 · 0 comments
Open

CTAPIBaseManager对象的dealloc调用问题 #36

TouchFriend opened this issue Sep 2, 2020 · 0 comments

Comments

@TouchFriend
Copy link

当viewController死亡后,CTAPIBaseManager的dealloc并没有如期调用,需要等到请求完毕时,才会调用。
下面代码的闭包对CTAPIBaseManager对象进行了强引用,所以没有如期死亡。这也跟旧框架RTNetworking代码不同,现在是这样设计的吗?

CTNetworking代码:
NSNumber *requestId = [[CTApiProxy sharedInstance] callApiWithRequest:request success:^(CTURLResponse *response) {
[self successedOnCallingAPI:response];
} fail:^(CTURLResponse *response) {
CTAPIManagerErrorType errorType = CTAPIManagerErrorTypeDefault;
if (response.status == CTURLResponseStatusErrorCancel) {
errorType = CTAPIManagerErrorTypeCanceled;
}
if (response.status == CTURLResponseStatusErrorTimeout) {
errorType = CTAPIManagerErrorTypeTimeout;
}
if (response.status == CTURLResponseStatusErrorNoNetwork) {
errorType = CTAPIManagerErrorTypeNoNetWork;
}
[self failedOnCallingAPI:response withErrorType:errorType];
}];

RTNetworking代码:
#define AXCallAPI(REQUEST_METHOD, REQUEST_ID)
{
__weak typeof(self) weakSelf = self;
REQUEST_ID = [[CTApiProxy sharedInstance] call##REQUEST_METHOD##WithParams:apiParams serviceIdentifier:self.child.serviceType methodName:self.child.methodName success:^(CTURLResponse *response) {
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf successedOnCallingAPI:response];
} fail:^(CTURLResponse *response) {
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf failedOnCallingAPI:response withErrorType:CTAPIManagerErrorTypeDefault];
}];
[self.requestIdList addObject:@(REQUEST_ID)];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant