1

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

测试.h

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

测试.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
4

0 回答 0