Qt for IOS的坑总结与解决方案

来源:互联网 发布:王思聪退股熊猫tv 知乎 编辑:程序博客网 时间:2024/06/16 16:18

以下错误都是本人亲自采坑而来,出现率99%,在网上找到的解决方案很微妙,所以总结于此:


1、在使用AFNetworking第三方库时,导致编译不过报错:error: cannot synthesize weak property in file using manual reference counting


解决方案:这就是引入arc代码在项目中的冲突,有一种解决办法就是把资源代码中的weak修饰符改为assign,

但是这种方法毕竟是把别人写的代码给改了,有的时候往往会出现闪退、崩溃的问题。

比较好的解决办法就是项目配置文件->Build Phrases->Complie Sources,找到出现问题的资源库文件(比如weak修饰符所在的文件)

,双击Complie Files中的该文件,在空白行中写入-fobjc-arc,这样就可以有效防止该冲突。反过来有的时候,在arc代码中引入手动

管理内存的代码,我们在Complie Files中为新增的资源文件增加-fno-objc-arc,这样就避免了手动管理内存的代码在arc代码中的冲突。


2、编译报错Cannot create __weak reference in file using manual reference counting


解决方案:(根据Xcode自身版本对号入座,我使用的是xcode8.3)
build setting -> Apple LLVM8.3 - Language - Objective C -> Weak References in Manual Retain Release 设置为 YES


3、为防止文件未被xcode编译

 

在qt Creator工程Pro文件中.m文件除了在DISTFILES关键字后面追加,还要手动复制一份到OBJECTIVE_SOURCES关键字后面,

只在DISTFILES关键字后面追加文件,qt creator可以显示.m文件,但是xcode是不会编译进去的,只能最后手动再添加一遍,否则会编译报错。


4、建议

 

无论文件是否为qt文件还是ios文件,最好都要在xcode上面编译,以xcode软件报错为主,其次再回到qt creator编译,以qt creator报错为辅,

xcode编译过了才是真的编译过了!


5、将iosApp编译进真机后提示如下:
Could not launch “weClassApp”Verify the Developer App certificate for your account is trusted on your device.

Open Settings on XXX的 iPhone and navigate to General -> Device Management, then select your Developer

App certificate to trust it.

 

解决方法:手机(真机)中点击设置(Settings) -》 通用(General)-》设备管理(Device Management)-》点击对应的id -》信任(Trust)


6、错误:App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.

Temporary exceptions can be configured via your app's Info.plist file

 

解决方法:
io9的时候因为强制使用了https协议,所以需要在info文件中添加如下字段:<建议在 xocde中的info修改,直接在info.plist可能会不生效,亲测!>
NSAppTransportSecurity
NSAllowsArbitraryLoads 设置为YES。


或者直接编辑Info.plist,在最后 tag 前添加:<可能会不生效>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>

原创粉丝点击