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;
}
computeHash
? – Lu_