Unknown type name "NSString"解决方案

今天看到个问题,编辑工程提示Unknown type name 'NSString',如下图

 

导致出现异常的原因是是因为工程中添加了ZipArchive(第三方开源解压缩库)

 

一般情况下出现“Unknown type name”是头文件互相引用出现的,这里可以排除,由于源码使用是c\c++与oc混编,

考虑新的XCode编译文件类型导致的,尝试了几种方案,下面三种可以解决问题。

 

解决方案一:

选择所有.c文件,将属性的 identity and type 改为Objective-C Source。

解决方案二:

选择所有.c文件,将.c修改为.m

 

解决方案三:

将Compile Sources As 改为 Objective-C++

方案三由于修改所有文件的编译类型,所有可能会导致其他包括c、c++代码的提示错误,不过都是些的提示异常,按提示修改即可。


zz http://www.bkjia.com/IOSjc/748209.html

// MARK: - 加载真实设备数据 private func loadRealDeviceData() { guard let appContext = TPSmartHomeAppContext.sharedInstance() else { return } let defaultGroupId = "" let devices = appContext.devices(inDeviceGroup: defaultGroupId, includingHiddenChannels: false) .filter { !$0.channelsInfo.isEmpty || $0.displayType == .IPC } DispatchQueue.main.async { self.deviceListView.configure(withDevices: devices) { [weak self] channel, device in self?.handleChannelSelected(channel, ofDevice: device) } // 动态更新高度 let newHeight = self.deviceListView.calculateHeight(containerWidth: self.view.bounds.width) self.deviceListView.snp.updateConstraints { make in make.height.equalTo(newHeight) } self.tableView.beginUpdates() self.tableView.endUpdates() } } private func handleChannelSelected(_ channel: TPSSChannelInfo, ofDevice device: TPSSDeviceForDeviceList) { print("点击了设备 \(device.alias ?? "Unknown") 的通道 \(channel.name)") // 示例跳转逻辑 let previewVC = LivePreviewViewController(device: device, channel: channel) navigationController?.pushViewController(previewVC, animated: true) } Cannot find 'TPSmartHomeAppContext' in scope Cannot infer contextual base in reference to member 'IPC' Extra trailing closure passed in call Left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used String interpolation produces a debug description for an optional value; did you mean to make this explicit? Cannot find 'LivePreviewViewController' in scope 仔细检查错误,如果需要什么接口的详细信息说出来我找到发给你
12-09
#import "TPNetResqustManager.h" #import <TPHTTPClient/TPHTTPClient.h> #import <TPHandle-ObjC/TPHandle.h> #import <TPHandle-ObjC/TPGCDReprocessHandle.h> #import <TPHandle-ObjC/TPAbstractHandle.h> #import <TPHTTPClient/TPHTTPResponse.h> #import <TPHTTPClient/TPHTTPResponseConfig.h> #import "TPSecurityPolicy.h" #import "TPNetworkUtil.h" @interface TPNetResqustManager() <NSURLSessionDelegate> @property(nonatomic, strong) dispatch_queue_t seriaQueue; @property(nonatomic, strong) NSMutableDictionary *serverDomain; @end static const NSInteger kTPRequestTimeOut = 30; @implementation TPNetResqustManager - (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler{ NSURLCredential *card = [[NSURLCredential alloc] initWithTrust:challenge.protectionSpace.serverTrust]; completionHandler(NSURLSessionAuthChallengeUseCredential,card); } + (instancetype)shareInstance { static dispatch_once_t onceToken; static TPNetResqustManager *instance = nil; dispatch_once(&onceToken, ^{ if (instance == nil) { instance = [super allocWithZone:nil]; instance.seriaQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_SERIAL); instance.serverDomain = [NSMutableDictionary new]; } }); return instance; } + (instancetype)allocWithZone:(struct _NSZone *)zone { return [TPNetResqustManager shareInstance]; } #pragma mark - + (void)postWithUrl:(NSString *)url params:(NSDictionary *)params succeedBlk:(TPNetSucceedBlk)sucBlk failureBlk:(TPNetFailureBlk)failureBlk { [self postWithUrl:url header:nil params:params succeedBlk:sucBlk failureBlk:failureBlk]; } + (void)getWithUrl:(NSString *)url params:(NSDictionary *)params succeedBlk:(TPNetSucceedBlk)sucBlk failureBlk:(TPNetFailureBlk)failureBlk { [self getWithUrl:url header:nil params:params succeedBlk:sucBlk failureBlk:failureBlk]; } + (void)postWithUrl:(NSString *)url header:(NSDictionary *)header params:(NSDictionary *)params succeedBlk:(TPNetSucceedBlk)sucBlk failureBlk:(TPNetFailureBlk)failureBlk { [self requstWithUrl:url header:header method:TPHTTPRequestConfigRequestMethodPOST params:params succeedBlk:sucBlk failureBlk:failureBlk]; } + (void)getWithUrl:(NSString *)url header:(NSDictionary *)header params:(NSDictionary *)params succeedBlk:(TPNetSucceedBlk)sucBlk failureBlk:(TPNetFailureBlk)failureBlk { [self requstWithUrl:url header:header method:TPHTTPRequestConfigRequestMethodGET params:params succeedBlk:sucBlk failureBlk:failureBlk]; } + (void)requstWithUrl:(NSString *)url header:(NSDictionary *)header method:(NSString *)method params:(NSDictionary *)params succeedBlk:(TPNetSucceedBlk)sucBlk failureBlk:(TPNetFailureBlk)failureBlk { TPHTTPRequest *request = [TPHTTPRequest new]; request.timeout = kTPRequestTimeOut; request.httpConfig.url = url; request.httpConfig.method = method; [request.httpConfig.header addEntriesFromDictionary:[TPNetworkUtil defaultHeaders]]; header ? [request.httpConfig.header addEntriesFromDictionary:header] : nil; [TPNetResqustManager shareInstance].reqHeaderBlk ? [TPNetResqustManager shareInstance].reqHeaderBlk(request.httpConfig.header) : nil; #if DEBUG NSLog(@"tprequest:%@ \nheader:%@ \nbody:%@\n", url, header, params); #endif request.httpConfig.body = params; NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"tp-link-CA.der"]; // TPHTTPClient *client = [self certClient:path]; TPHTTPClient *client = [self defaultClient]; [TPGCDReprocessHandle reprocessFromHandle:[client sendRequest:request] queue:dispatch_get_main_queue() reprocessAction:^TPHandleResult * _Nullable(TPHandleResult<TPHTTPResponse *> * _Nonnull result) { [client.sessionManager.session finishTasksAndInvalidate]; if (!result.success) { NSDictionary *codeDict = @{ @"httpStatusCode": @(result.obj.httpConfig.statusCode), @"httpErrorCode": @(result.obj.httpConfig.urlErrorDomainCode), }; NSMutableDictionary *dict = [NSMutableDictionary new]; dict[@"statusCode"] = codeDict; if (result.obj.httpConfig.body) { dict[@"content"] = result.obj.httpConfig.body; } NSError *err = [NSError errorWithDomain:@"tplink.com" code:1 userInfo:dict]; failureBlk ? failureBlk(err) : nil; return nil; } sucBlk ? sucBlk(result.obj.httpConfig.body) : nil; return nil; }]; } #pragma mark - Private + (TPHTTPClient *)defaultClient { return [self certClient:@""]; } + (TPHTTPClient *)certClient:(NSString *)certPath { TPHTTPClient *client = [TPHTTPClient new]; NSMutableSet *types = client.sessionManager.responseSerializer.acceptableContentTypes.mutableCopy; [types addObjectsFromArray:@[@"application/json", @"text/json", @"text/javascript", @"text/html", @"text/plain"]]; client.sessionManager.responseSerializer.acceptableContentTypes = types; NSData *data = [NSData dataWithContentsOfFile:certPath.length > 0 ? certPath : @""]; if (data) { AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate withPinnedCertificates:[NSSet setWithObject:data]]; policy.allowInvalidCertificates = YES; policy.validatesDomainName = YES; client.sessionManager.securityPolicy = policy; } else { client.sessionManager.securityPolicy = [TPSecurityPolicy defaultPolicy]; } return client; } @end .m,这就能直接使用了吗?假如我有一个接口url的话
最新发布
12-16
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值