多语言配置以及删除配置
此处应该有张图片---
删除配置:选中中英翻译文件,Xcode右侧不再选中即可
涉及到隐私图片时,需要SD_webImage携带token请求图片,一般该设置会在新token返回的地方设置
-(void)setNewToken:(NSURLSessionDataTask *)task{
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
if (response.statusCode==401) {
//todo
}
NSDictionary *allHeaders = response.allHeaderFields; NSLog(@"allHeaders:%@",allHeaders);
if ([self dictionary:allHeaders ContainsObject:@"Authorization"]) {
NSString *header = [allHeaders valueForKey:@"Authorization"];
header = [header stringByReplacingOccurrencesOfString:@"XXXXX" withString:@""];
header = [header stringByReplacingOccurrencesOfString:@" " withString:@""];
if (header.length>0) {
[[NSUserDefaults standardUserDefaults] setObject:header forKey:userTokenSaveInDefaultKey];
}
}
}
-(void)initHttpSessionManager {
_httpSessionManager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:self.currentHost]];
//----------------------------配置版本号
[_httpSessionManager.requestSerializer setValue:@"XX/XX.XXXXX.v1+json" forHTTPHeaderField:@"accept"];
//----------------------------配置token
NSString *userToken = [[NSUserDefaults standardUserDefaults] objectForKey:userTokenSaveInDefaultKey];
[_httpSessionManager.requestSerializer setValue:[NSString stringWithFormat:@"XXXXX %@",userToken] forHTTPHeaderField:@"Authorization"];
//---------------------------sd_webImage附带token请求
SDWebImageDownloader *sd = [SDWebImageManager sharedManager].imageDownloader;
[sd setValue:[NSString stringWithFormat:@"XXXXX %@",userToken] forHTTPHeaderField:@"Authorization"];
//----------------------------
[_httpSessionManager.requestSerializer setValue: @"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
_httpSessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:
@"application/json",
@"text/json",
@"text/plain",
@"text/html",
@"text/javascript",
nil];
//配置https
// _httpSessionManager.securityPolicy = [self customSecurityPolicy];
// AFSecurityPolicy *securityPolicy = [[AFSecurityPolicy alloc] init];
// [securityPolicy setAllowInvalidCertificates:YES];
// _httpSessionManager.securityPolicy = securityPolicy;
// _httpSessionManager.securityPolicy.allowInvalidCertificates = YES;
// 设置超时时间
[_httpSessionManager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
_httpSessionManager.requestSerializer.timeoutInterval = self.defaultSeconds;
[_httpSessionManager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
}
重点
//----------------------------配置token
NSString *userToken = [[NSUserDefaults standardUserDefaults] objectForKey:userTokenSaveInDefaultKey];
[_httpSessionManager.requestSerializer setValue:[NSString stringWithFormat:@"XXXX %@",userToken] forHTTPHeaderField:@"Authorization"];
//sd_webImage附带token请求
SDWebImageDownloader *sd = [SDWebImageManager sharedManager].imageDownloader;
[sd setValue:[NSString stringWithFormat:@"XXXXXX %@",userToken] forHTTPHeaderField:@"Authorization"];
//----------------------------
XMNetworking表单形式提交config.generalHeaders = @{@"Content-Type": @"application/x-www-form-urlencoded"};
[XMCenter setupConfig:^(XMConfig *config) {
config.generalServer = SZURL_BASE_DEV;
//config.generalHeaders = @{@"Content-Type": @"text/html; charset=utf-8"};
//config.generalParameters = @{@"general-parameter": @"general parameter value"};
config.generalHeaders = @{@"Content-Type": @"application/x-www-form-urlencoded"};
config.generalUserInfo = nil;
config.callbackQueue = dispatch_get_main_queue();
config.engine = [XMEngine sharedEngine];
#ifdef DEBUG
config.consoleLog = YES;
#endif
}];
以及下载一些别的文件
-(void)downLoadImageWithParms:(NSDictionary *)parms Success:(void (^)(id responseObject) )SuccessBlock Failure:(void (^)(NSError * _Nonnull error))failureBlock{
NSString *url = parms[@"url"];
if (url.length==0) return;
[XMCenter sendRequest:^(XMRequest *request) {
request.url = url;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory=[paths objectAtIndex:0];
request.downloadSavePath = [NSHomeDirectory() stringByAppendingString:@"/Documents/"];
request.requestType = kXMRequestDownload;
NSString *userToken = [[NSUserDefaults standardUserDefaults] objectForKey:userTokenSaveInDefaultKey];
request.headers=@{@"Content-Type":@"application/x-www-form-urlencoded",@"Authorization":[NSString stringWithFormat:@"XXXXXX %@",userToken]};
} onProgress:^(NSProgress *progress) {
// the progress block is running on the session queue.
if (progress) {
NSLog(@"onProgress: %f", progress.fractionCompleted);
}
} onSuccess:^(id responseObject) {
NSLog(@"onSuccess: %@", responseObject);
if (SuccessBlock) {
SuccessBlock(responseObject);
}
} onFailure:^(NSError *error) {
NSLog(@"onFailure: %@", error);
failureBlock(error);
}];
}
执行pod install 出错
➜ opf-ios-rider pod install
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.5.3/lib/cocoapods/command.rb:118:in `git_version': Failed to extract git version from `git --version` ("xcrun: error: active developer path (\"/Applications/Xcode.app/Contents/Developer\") does not exist\nUse `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.\nSee `man xcode-select` for more details.\n") (RuntimeError)
from /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.5.3/lib/cocoapods/command.rb:130:in `verify_minimum_git_version!'
from /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.5.3/lib/cocoapods/command.rb:49:in `run'
from /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.5.3/bin/pod:55:in `<top (required)>'
from /usr/local/bin/pod:22:in `load'
from /usr/local/bin/pod:22:in `<main>'
卸载xcodeproj和cocoapods后从新安装
sudo gem uninstall xcodeproj
sudo gem uninstall cocoapods
sudo gem install xcodeproj
sudo gem install cocoapods
sudo gem update --system
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem
➜ ~ sudo gem install cocoapods
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
➜ ~ sudo gem install -n /usr/local/bin cocoapods
Successfully installed cocoapods-1.7.0
Parsing documentation for cocoapods-1.7.0
Done installing documentation for cocoapods after 3 seconds
1 gem installed
➜ ~
xcode-select: note: install requested for command line developer tools
然鹅一堆操作之后才发觉了原因:电脑里原来存在了两个Xcode,刚才自己随手删除了旧的版本,需要执行sudo xcode-select --switch /Applications/Xcode.app
指定xcode,回想之前在新Xcode打不开模拟器也是这个原因。。。巴拉巴拉。。。
swift OC 混编报错
Showing Recent Messages
ld: warning: Could not find auto-linked library 'swiftCoreFoundation'
Showing Recent Messages
ld: warning: Could not find auto-linked library 'swiftObjectiveC'
Showing Recent Messages
ld: warning: Could not find auto-linked library 'swiftQuartzCore'
Showing Recent Messages
ld: warning: Could not find auto-linked library 'swiftCore'
等等一堆信息
当纯OC项目调用swift库的时候项目必须要有一个swift文件,哪怕你不用它。
很不正常的一个状态:初次运行启动app首页展示出来之后卡顿了3s
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIApplication delegate]
PID: 5123, TID: 461328, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
4 OFRider 0x00000001009cc968 -[OFRWaitOrderController refresh] + 1396
5 CoreFoundation 0x00000001848415bc <redacted> + 20
6 CoreFoundation 0x0000000184841588 <redacted> + 64
7 CoreFoundation 0x0000000184840a7c <redacted> + 392
8 CoreFoundation 0x0000000184840728 <redacted> + 96
9 CoreFoundation 0x00000001847ba524 <redacted> + 1496
10 CoreFoundation 0x00000001848401d8 _CFXNotificationPost + 696
11 Foundation 0x0000000185228814 <redacted> + 68
12 OFRider 0x000000010072fa9c __46-[OFRHomeController postWaitOrderNotification]_block_invoke + 108
13 libdispatch.dylib 0x0000000102aa0c74 _dispatch_client_callout + 16
14 libdispatch.dylib 0x0000000102aa3ffc _dispatch_continuation_pop + 524
15 libdispatch.dylib 0x0000000102ab6610 _dispatch_source_invoke + 1444
16 libdispatch.dylib 0x0000000102aa3928 _dispatch_queue_override_invoke + 448
17 libdispatch.dylib 0x0000000102ab1dc8 _dispatch_root_queue_drain + 372
18 libdispatch.dylib 0x0000000102ab27ac _dispatch_worker_thread2 + 156
19 libsystem_pthread.dylib 0x00000001844f11b4 _pthread_wqthread + 464
20 libsystem_pthread.dylib 0x00000001844f3cd4 start_wqthread + 4
2019-05-29 10:36:33.922136+0800 OFRider[5123:461328] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication delegate]
PID: 5123, TID: 461328, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
4 OFRider 0x00000001009cc968 -[OFRWaitOrderController refresh] + 1396
5 CoreFoundation 0x00000001848415bc <redacted> + 20
6 CoreFoundation 0x0000000184841588 <redacted> + 64
7 CoreFoundation 0x0000000184840a7c <redacted> + 392
8 CoreFoundation 0x0000000184840728 <redacted> + 96
9 CoreFoundation 0x00000001847ba524 <redacted> + 1496
10 CoreFoundation 0x00000001848401d8 _CFXNotificationPost + 696
11 Foundation 0x0000000185228814 <redacted> + 68
12 OFRider 0x000000010072fa9c __46-[OFRHomeController postWaitOrderNotification]_block_invoke + 108
13 libdispatch.dylib 0x0000000102aa0c74 _dispatch_client_callout + 16
14 libdispatch.dylib 0x0000000102aa3ffc _dispatch_continuation_pop + 524
15 libdispatch.dylib 0x0000000102ab6610 _dispatch_source_invoke + 1444
16 libdispatch.dylib 0x0000000102aa3928 _dispatch_queue_override_invoke + 448
17 libdispatch.dylib 0x0000000102ab1dc8 _dispatch_root_queue_drain + 372
18 libdispatch.dylib 0x0000000102ab27ac _dispatch_worker_thread2 + 156
19 libsystem_pthread.dylib 0x00000001844f11b4 _pthread_wqthread + 464
20 libsystem_pthread.dylib 0x00000001844f3cd4 start_wqthread + 4
关键信息
Main Thread Checker: UI API called on a background thread: -[UIApplication delegate]
PID: 5123, TID: 461328, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
以及
2019-05-29 10:36:33.922136+0800 OFRider[5123:461328] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication delegate]
PID: 5123, TID: 461328, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
主线程检测器(Main Thread Checker)
app首次安装时出现请求报[BoringSSL] nw_protocol_boringssl_error(1584) 错误。
2019-04-22 14:15:07.985454+0800 OFStore[1291:154097] [BoringSSL] nw_protocol_boringssl_error(1584) [C1.10:2][0x135ec0030] Lower protocol stack error: 54
2019-04-22 14:15:07.986618+0800 OFStore[1291:154097] TIC TCP Conn Failed [1:0x281366b80]: 1:54 Err(54)
2019-04-22 14:15:07.992404+0800 OFStore[1291:154097] Task <745FCC9A-D561-4120-8618-A9B38170E12E>.<1> HTTP load failed (error code: -1005 [1:54])
2019-04-22 14:15:07.992664+0800 OFStore[1291:154097] Task <745FCC9A-D561-4120-8618-A9B38170E12E>.<1> finished with error - code: -1005
2019-04-22 14:15:08.290688+0800 OFStore[1291:154087] [Fabric] failed to download settings Error Domain=FABNetworkError Code=-5 "(null)" UserInfo={status_code=403, type=2, request_id=70c4645204c8a4c7180ce6ebebbb55c8, content_type=application/json; charset=utf-8}
2019-04-22 14:15:09.503203+0800 OFStore[1291:154097] [BoringSSL] nw_protocol_boringssl_error(1584) [C3.10:2][0x135e80590] Lower protocol stack error: 54
2019-04-22 14:15:09.503778+0800 OFStore[1291:154097] TIC TCP Conn Failed [3:0x28136ce40]: 1:54 Err(54)
2019-04-22 14:15:09.508035+0800 OFStore[1291:154097] Task <2D1270F2-458C-4C85-935B-04E5FA4788F7>.<1> HTTP load failed (error code: -1005 [1:54])
2019-04-22 14:15:09.508296+0800 OFStore[1291:154097] Task <2D1270F2-458C-4C85-935B-04E5FA4788F7>.<1> finished with error - code: -1005
2019-04-22 14:17:07.331686+0800 OFStore[1291:154048] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C6.1:2][0x135e85a30] get output frames failed, state 8196
2019-04-22 14:17:07.331847+0800 OFStore[1291:154048] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C6.1:2][0x135e85a30] get output frames failed, state 8196
2019-04-22 14:17:07.332264+0800 OFStore[1291:154048] TIC Read Status [6:0x0]: 1:57
2019-04-22 14:17:07.332294+0800 OFStore[1291:154048] TIC Read Status [6:0x0]: 1:57
2019-04-22 14:18:55.325783+0800 OFStore[1291:154048] XPC connection interrupted
请求相关第一反应就是有可能是后台接口问题,最终却在app端解决了。
- 涉及的原因:app启动加载根控制器时,创建触发了某些问题,具体原因我通过查看线程树、断点也没完整定位出来。
- 解决:首次启动改为无网络请求,让登录页作为根控制器(修改前我是让首页作为根控制器,再根据条件弹出登录页)。
OC -> swift 传值类型不匹配。
Thread 1: Fatal error: NSArray element failed to match the Swift Array Element type
网友评论