为什么行: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