前言
日常開發(fā)遇到的問題記錄。
JSON
Invalid type in JSON write (NSConcreteMutableData)
合法的json對(duì)象:
- 1、頂層對(duì)象必須是NSArray或者NSDictionary;
- 2、所有的對(duì)象必須是
NSString/NSNumber/NSArray/NSDictionary/NSNull
的實(shí)例; - 3、所有NSDictionary的key必須是NSString類型;
- 4、數(shù)字對(duì)象不能是非數(shù)值或無窮;
內(nèi)購
1、銀行cnaps code查詢
2、申請(qǐng)賬號(hào)時(shí),無法加入program
蘋果說:
Sorry, you can’t enroll at this time. You can still develop apps and test them on iOS devices using the beta version of Xcode. Learn more
原因: 按照注冊(cè)的時(shí)候填寫的出生日期, 年齡未滿18歲。
解決方法:
- 重新注冊(cè)apple id;
- 在apple.com修改appid的信息;
iOS10
1、未找到應(yīng)用程序的“aps-environment”的授權(quán)字符串
"getting push token failed: Error Domain=NSCocoaErrorDomain Code=3000 "未找到應(yīng)用程序的“aps-environment”的授權(quán)字符串" UserInfo={NSLocalizedDescription=未找到應(yīng)用程序的“aps-environment”的授權(quán)字符串}
解決方案:打開Xcode8,點(diǎn)擊下面的地方。
2、去掉無效log并且保留原來的nslog信息
真機(jī)下設(shè)置OS_ACTIVITY_MODE會(huì)讓nslog的信息消失,可以把nslog改成printf。
#define LYLog(...) printf("%f %s\n",[[NSDate date]timeIntervalSince1970],[[NSString stringWithFormat:__VA_ARGS__]UTF8String]);
Debug
1、dSYM
當(dāng)把Objective-C代碼編譯成匯編、再轉(zhuǎn)譯成二進(jìn)制機(jī)器碼后,會(huì)生成一個(gè)dSYM文件包(內(nèi)含符號(hào)表,負(fù)責(zé)翻譯崩潰報(bào)告成可讀代碼)。
.dSYM文件是一個(gè)目錄,包含一個(gè)十六進(jìn)制的函數(shù)地址映射信息的文件,Debug的symbols都在這個(gè)文件中(包括文件名、函數(shù)名、行號(hào)等)。
Xcode項(xiàng)目每次編譯后,都會(huì)生成一個(gè)新的.dSYM文件,故而真機(jī)上的崩潰日志需要檢查對(duì)應(yīng)的符號(hào)表。
2、crash日志分析
WAKEUPS 錯(cuò)誤
http://stackoverflow.com/questions/25848441/app-shutdown-with-exc-resource-wakeups-exception-on-ios-8-gm
后臺(tái)線程有嚴(yán)格的調(diào)用限制
Background threads in iOS 8 have a hard limit on how many times you can run a sleep/wake cycle on each thread per second, and having a high count here is usually an indication that something is wrong / inefficient in your thread management.
Xcode
1、Xcode斷點(diǎn)失效
- Clean Project
- Clean Build Folder
- Clear Xcode's DerivedData
- Making sure breakpoints are enabled (Cmd Y)
- Build Settings are set to Debug
- Always Show Disassembly enabled and disabled
- Debugging enabled in run config
最后發(fā)現(xiàn)問題出現(xiàn)在Xcode工程,當(dāng)把老工程的文件全部添加到新工程即可斷點(diǎn)。(老工程新建于2013年,猜測(cè)是這個(gè)原因;可惜沒有找到斷點(diǎn)失效的真正原因)
2、Xcode并存
在finder中打開應(yīng)用程序,把xcode改成xcode8,再下載xcode7;
pod相關(guān)
diff: /../Podfile.lock: No such file or directory
diff: /Manifest.lock: No such file or directory
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
刪除podfile.lock 和 工程,重新pod install
需要注意查看pod install的指令,反饋結(jié)果。
集成報(bào)錯(cuò)
1、找不到KSYGPUStreamerKit
KSYRTCStreamerKit 繼承 KSYGPUStreamerKit,
但是沒有引入頭文件,使用的是 @class KSYGPUStreamerKit;
于是在使用KSYRTCStreamerKit 必須先導(dǎo)入KSYGPUStreamerKit,
再導(dǎo)入KSYRTCStreamerKit。
給出的demo中,頭文件的引用是
#import <libksyrtclivedy/KSYRTCStreamerKit.h>
#import <libksyrtclivedy/KSYRTCStreamer.h>
#import <libksygpuliveDy/libksygpuimage.h>
#import <libksygpuliveDy/KSYGPUStreamerKit.h>
這樣第三方在集成的時(shí)候,如果按照demo的頭文件引入順序,就會(huì)報(bào)奇怪的錯(cuò)誤。
2、運(yùn)行時(shí)錯(cuò)誤
運(yùn)行時(shí)報(bào)錯(cuò):
dyld: Library not loaded:@rpath/GPUImage.framework/GPUImage Referenced
Reason: image not found
原因是運(yùn)行時(shí)沒找到GPUImage
解決方案:embedd GPUImage.framework
UIWindow
UIWindow是第一個(gè)視圖控件(第一個(gè)對(duì)象是UIapplication),負(fù)責(zé)展示app內(nèi)容。
[self.window makekeyandvisible]
可以讓窗口成為主窗口,并且顯示出來。
其他的view依賴于Window,Window顯示出來后,view添加在Window上。
UIWindow的三個(gè)級(jí)別:WindowNormal 、Alert、StatusBar;
UIKIT_EXTERN const UIWindowLevel UIWindowLevelNormal;
UIKIT_EXTERN const UIWindowLevel UIWindowLevelAlert;
UIKIT_EXTERN const UIWindowLevel UIWindowLevelStatusBar __TVOS_PROHIBITED;
UIAlterView的例子:alert級(jí)別;
總結(jié)
作為iOS開發(fā),花在iOS的時(shí)間不是最多,反省反省反省。