简体   繁体   中英

Incompatible block pointer types - Objective-c

I want to call following code with return statement in main thread but I got below error.

Incompatible block pointer types passing 'NSString *(^)(void)' to parameter of type 'dispatch_block_t _Nonnull' (aka 'void (^)(void)')

Following is my code.

NSString *hash = [AGMobileService accessTokenHashForDate:date withParameters:[NSArray new]];


+ (NSString *)accessTokenHashForDate:(NSDate *)date withParameters:(NSArray *)params{

    dispatch_async(dispatch_get_main_queue(), ^{
      NSString *accessToken = ((AppDelegate *)[[UIApplication sharedApplication] delegate]).loginProfile.accessToken;

      NSString *paramsStr = [params componentsJoinedByString:@""];
      NSString *hashStr = [NSString stringWithFormat:@"%@%@%@%@", [CommonUtil IMEI], [date agileHashFormattedString], (!paramsStr) ? @"" : paramsStr, accessToken];
      return [AGMobileService computeHash:hashStr usingHash:HASH_SALT];
    });
}

+ (NSString *)computeHash:(NSString *)text usingHash:(NSString*)hashSalt {

    NSString *textToEncode = [NSString stringWithFormat:@"%@%@", hashSalt, text];
    NSData *data = [textToEncode dataUsingEncoding:NSUTF8StringEncoding];
    unsigned char hash[CC_SHA256_DIGEST_LENGTH];
    if ( CC_SHA256([data bytes], (int) [data length], hash) ) {
        NSData *sha256 = [NSData dataWithBytes:hash length:CC_SHA256_DIGEST_LENGTH];
        return [sha256 base64EncodedString];
    }
    return nil;
}

I have encountered things like this, I just remove the return code in the dispatch block, but I do not know the reason.So I also want to know the reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM