我收到警告:
Incompatible pointer types assigning to 'AFHTTPSessionManager *' from 'NSURLSessionDataTask * _Nullable'
'POST:parameters:success:failure:' is depreceated
尝试使用 AFNetworking 3.0 发出请求时。我想知道使用 AFNewtworking 3.0 为使用 iOS 7.0 或更高版本的应用程序发出发布请求的正确方法是什么。这是我的代码:
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager setResponseSerializer:[SignupResponseSerializer serializer]];
__weak typeof(self)weakSelf = self;
NSString *urlString = [NSString stringWithFormat:@"%s%s", kBaseURL, kRegisterURL];
NSData *plainData = UIImagePNGRepresentation(self.profilePicture);
NSString *base64String = [plainData base64EncodedStringWithOptions:0];
if (self.firstNameField.text && self.lastNameField.text && self.passwordField.text && self.emailField.text) {
NSDictionary *params = @{ @"first_name": self.firstNameField.text, @"last_name": self.lastNameField.text, @"password": self.passwordField.text, @"email": self.emailField.text, @"avatar_data": base64String};
self.sessionManager = [manager POST:urlString parameters:params success:^(NSURLSessionTask *task, id responseObject) {
NSDictionary *JSON = [responseObject objectAtIndex:0];
NSString *token = JSON[@"auth_token"];
NSString *avatarURL = JSON[@"avatar_url"];
weakSelf.credentialStore.avatarURL = avatarURL;
weakSelf.credentialStore.authToken = token;
weakSelf.credentialStore.firstName = self.firstNameField.text;
weakSelf.credentialStore.lastName = self.lastNameField.text;
weakSelf.credentialStore.email = self.emailField.text;
weakSelf.credentialStore.password = self.passwordField.text;
[SVProgressHUD dismiss];
[self dismissViewControllerAnimated:YES completion:nil];
} failure:^(NSURLSessionTask *task, NSError *error) {
// if (task.isCancelled) {
// return;
// }
[SVProgressHUD showErrorWithStatus:@"Login Failed"];
NSLog(@"%@", error);
}];
}