iOS 随手记一二

  • 多语言配置以及删除配置

此处应该有张图片---

删除配置:选中中英翻译文件,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)

猜你喜欢

转载自blog.csdn.net/weixin_34115824/article/details/91007243