【发布时间】:2020-02-19 08:58:24
【问题描述】:
我收到警告 [UIApplication delegate] must be used from main thread only in the below line of code
((AppDelegate *)[[UIApplication sharedApplication] 委托]).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
}
谁能告诉我如何删除这个警告信息?
【问题讨论】:
-
首先你不应该在应用代理上保留登录配置文件。
-
@Lu_我同意你的观点,但这是遗留代码,现在我不想更改它。
-
所以唯一的方法是在主线程上使用应用委托,使用块来返回 hashStr 因为它将是异步的,无论如何都会有很多重构
标签: ios objective-c