這裏是我的代碼部分:聊齋志異 「殭屍」 在forwardInvocation:+ getArgument:atIndex方法
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = [[UIScreen mainScreen] bounds];
_webView = [[UIWebView alloc] initWithFrame:frame];
[_webView setHidden:NO];
[self.view addSubview:_webView];
_vk = [[DPVkontakteCommunicator alloc] initWithWebView:_webView];
DPVkontakteUserAccount *user;
NSString *accessToken = [[NSUserDefaults standardUserDefaults]
objectForKey:@"accessToken"];
NSInteger userId = [[[NSUserDefaults standardUserDefaults]
objectForKey:@"userId"] integerValue];
user = [[DPVkontakteUserAccount alloc]
initUserAccountWithAccessToken:accessToken
userId:userId];
NSLog(@"%@", user);
[user setSuccessBlock:^(NSDictionary *dictionary)
{
NSLog(@"%@", dictionary);
}];
NSDictionary *options = @{@"uid":@"1"};
// [user usersGetWithCustomOptions:@{@"uid":@"1"}]; // Zombie
[user usersGetWithCustomOptions:options]; // Not zombie
// __block NSDictionary *options = @{};
//
// [_vk startOnCancelBlock:^{
// NSLog(@"Cancel");
// } onErrorBlock:^(NSError *error) {
// NSLog(@"Error: %@", error);
// } onSuccessBlock:^(DPVkontakteUserAccount *account) {
// NSLog(@"account:%@", account);
//
// [account setSuccessBlock:^(NSDictionary *dictionary)
// {
// NSLog(@"%@", dictionary);
// }];
//
// [account docsGetUploadServerWithCustomOptions:options];
// }];
}
這裏是處理userGetWithCustomOptions部分:方法:
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
NSString *methodName = NSStringFromSelector([anInvocation selector]);
NSDictionary *options;
[anInvocation getArgument:&options
atIndex:2];
NSArray *parts = [self parseMethodName:methodName];
NSString *vkURLMethodSignature = [NSString stringWithFormat:@"%@%@.%@",
kVKONTAKTE_API_URL,
parts[0],
parts[1]];
// appending params to URL
NSMutableString *fullRequestURL = [vkURLMethodSignature mutableCopy];
[fullRequestURL appendString:@"?"];
[options enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop)
{
[fullRequestURL appendFormat:@"%@=%@&", key, [obj encodeURL]];
}];
[fullRequestURL appendFormat:@"access_token=%@", _accessToken];
// performing HTTP GET request to vkURLMethodSignature URL
NSURL *url = [NSURL URLWithString:fullRequestURL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation;
operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:urlRequest
success:^(NSURLRequest *request,
NSHTTPURLResponse *response,
id JSON)
{
_successBlock(JSON);
}
failure:^(NSURLRequest *request,
NSHTTPURLResponse *response,
NSError *error,
id JSON)
{
_errorBlock(error);
}];
[operation start];
}
問題當我使用「選項」變量 - 它工作正常,但使用直接值時 - 失敗,應用程序崩潰。使用配置文件我發現方法調用指向釋放對象。
爲什麼會發生這種情況? 沒有其他可以提供幫助的代碼。
ViewController.m代碼:https://gist.github.com/AndrewShmig/5398546
DPVkontakteUserAccount.m:https://gist.github.com/AndrewShmig/5398557
您可以加入至少剩餘部分來自'DPVkontakeUserAccount'的'forwardInvocation:'方法,並將第一個代碼示例放在上下文中 - 特別是在調用'usersGetWithCustomOptions:'之後特別引用了'options'變量?這可能會幫助民間人士幫助你。 – CRD
@CRD現在可以嗎? – AndrewShmig
我相信這會幫助人們。你說「使用配置文件我發現方法調用指向釋放對象。」,哪個方法調用?任何機會'enumerateKeysAndObjectsUsingBlock:'? – CRD