gpt4 book ai didi

ios - 警告-[UIApplication delegate] 只能在主线程中使用

转载 作者:行者123 更新时间:2023-11-29 05:22:38 25 4
gpt4 key购买 nike

我收到警告 [UIApplication delegate] 必须仅在下面的代码行中从主线程使用

((AppDelegate *)[[UIApplication sharedApplication] delegate]).loginProfile.accessToken;

以下是我的代码。

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

NSString *accessToken = ((AppDelegate *)[[UIApplication sharedApplication] delegate]).loginProfile.accessToken;

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

谁能告诉我如何删除此警告消息?

最佳答案

+ (NSString *)accessTokenHashForDate:(NSDate *)date withParameters:(NSArray *)params{
__block NSString *accessToken = NULL;
if ([NSThread isMainThread]) {
accessToken = ((AppDelegate *)[[UIApplication sharedApplication] delegate]).loginProfile.accessToken;


} else {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_async(dispatch_get_main_queue(), ^{
accessToken = ((AppDelegate *)[[UIApplication sharedApplication] delegate]).loginProfile.accessToken;
dispatch_semaphore_signal(semaphore);
});
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_semaphore_signal(semaphore);
}
NSString *paramsStr = [params componentsJoinedByString:@""];
NSString *hashStr = [NSString stringWithFormat:@"%@%@%@%@", [CommonUtil IMEI], [date agileHashFormattedString], (!paramsStr) ? @"" : paramsStr, accessToken];
return hashStr;

}

关于ios - 警告-[UIApplication delegate] 只能在主线程中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58517313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com