FBRequest无法在NSOperation中运行

时间:2012-12-18 06:26:27

标签: objective-c facebook block nsoperation

为什么行:NSLog(@"request complete");不起作用? 只有在FBRequest完成时才会调用块内的代码。我认为在此期间,我的操作将从NSOperationQueue中删除,并且不会调用该块。

test.h

#import <Foundation/Foundation.h>
@interface test: NSOperation;
@end

test.m

#import "test.h"
@implementation test

- (void)start {
    [self willChangeValueForKey:@"isExecuting"];
    _isExecuting = YES;
    [self didChangeValueForKey:@"isExecuting"];

    [self loadFBRequest];
}

- (BOOL)isConcurrent {
    return YES;
}

- (void)finish {
    [self willChangeValueForKey:@"isExecuting"];
    [self willChangeValueForKey:@"isFinished"];

    _isExecuting = NO;
    _isFinished = YES;

    [self didChangeValueForKey:@"isExecuting"];
    [self didChangeValueForKey:@"isFinished"];
}

- (void)loadFBRequest {
    FBRequestConnection *conn = [[FBRequestConnection alloc] init];

    // Example: Get my info
    FBRequest *request = [FBRequest requestForGraphPath:@"/me?fields=id,name"];
    [conn addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        if (!error) {
            NSLog(@"result=%@", result);
        }
        NSLog(@"request complete"); // Don't work!
        [self finish];
    }];
    [conn start];
}

@end

0 个答案:

没有答案