title: Bug 小記(貴金屬)
date: 2015-11-20 11:13:33
categories: iOS
tags: [Bug,貴金屬]
作者:秋兒(lvruifei@foxmail.com)
最近在修復(fù) APP 的 Bug妻坝,遇到了幾個(gè)因?qū)?SDK 不熟 造成的 Bug惊窖。如下:
</br>
Bug1:點(diǎn)擊獲取驗(yàn)證碼后刽宪,沒有進(jìn)行倒計(jì)時(shí),且不能再次點(diǎn)擊
使用 GCD 寫的倒計(jì)時(shí)界酒,源代碼:
_isCountDown = YES;
__block int timeout=kCountdownTime; //倒計(jì)時(shí)時(shí)間
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒執(zhí)行
dispatch_source_set_event_handler(_timer, ^{
if(timeout<=0){ //倒計(jì)時(shí)結(jié)束,關(guān)閉
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
[self.getSmsCodeBtn setTitle:@"重新獲取" forState:UIControlStateNormal];
[self.getSmsCodeBtn setTitleColor:ColorWithHexString(GJS_COLOR_LOGINBTN_AVAILABLE_NORMAL) forState:UIControlStateNormal];
[self.getSmsCodeBtn setEnabled:YES];
_isCountDown = NO;
});
}else{
NSString *strTime = [NSString stringWithFormat:@"%ds后重發(fā)",timeout];
dispatch_async(dispatch_get_main_queue(), ^{
[self.getSmsCodeBtn setTitle:strTime forState:UIControlStateNormal];
[self.getSmsCodeBtn setTitleColor:ColorWithHexString(GJS_COLOR_GETCODEBTN_UNAVAILABLE) forState:UIControlStateNormal];
});
timeout--;
}
});
dispatch_resume(_timer);
如上所示的源碼毁欣,在 iOS7 上倒計(jì)時(shí)按鈕上的文字不會變化,在 iOS 8,iOS9 上都是沒問題的凭疮,我也郁悶了很久饭耳。各種百度未果后轉(zhuǎn)向 Google,也有人遇到這樣的問題,但是只搜索到一篇真正能解決這個(gè)問題的文章 http://blog.csdn.net/zhangyanshen/article/details/46910515
<font color=green>解決方案:</font>
[sendAuthCodeBtn setTitle:@"發(fā)送驗(yàn)證碼" forState:UIControlStateDisabled];
關(guān)鍵在于這行代碼执解。設(shè)置了禁用狀態(tài)下的文字。順利解決了 這個(gè) Bug衰腌。
</br>
Bug2:倒計(jì)時(shí) UIButton 上的文字變更會有閃爍效果
UIButton 設(shè)置 title時(shí)會閃爍右蕊。
<font color=brown>原因:</font>UIButton 的 buttonType 是 System 類型時(shí)會出現(xiàn)該種問題
<font color=green>解決方案:</font>UIButton 的 buttonType 設(shè)置為 Custom 類型時(shí)不會出現(xiàn)閃爍饶囚。
</br>
Bug3:在工程中添加plist 文件,用代碼對其進(jìn)行寫入操作坯约,在模擬器中按代碼執(zhí)行闹丐,但在真機(jī)上plist中內(nèi)容未改變
plist 文件中是一個(gè)數(shù)組被因,元素是多個(gè)字典卿拴,在模擬器上運(yùn)行一切正常衫仑,但測試人員用真機(jī)測試時(shí)發(fā)現(xiàn)問題,無法寫入到 plist 文件中堕花。
<font color=brown>原因:</font> 打包在 ipa 的文件是無法更改的文狱。一句話:無權(quán)限修改(知道真相的我眼淚掉下來~),只可進(jìn)行讀取操作缘挽。
<font color=green>解決方案:</font>在 app 啟動的時(shí)候判斷是否在 Document 文件夾下存在相同的 plsit 文件瞄崇。 不存在,獲取沙盒下 plist 文件中的內(nèi)容壕曼,并寫入Document 文件夾下的 plsit 文件苏研。存在則不做任何處理。(之所以選擇這種方式而不選擇直接將內(nèi)容用代碼寫入 Document 文件夾下來解決這個(gè)問題腮郊,是因?yàn)閭€(gè)人認(rèn)為在開發(fā)時(shí)方便對工程中plsit 文件內(nèi)容的更改)
</br>
<font color=pinkw>更新時(shí)間:2016年1月20日</font>
Bug1:進(jìn)入某個(gè)頁面摹蘑,App崩潰,崩潰原因是:[NSCFType set]: unrecognized selector sent to instance 0x4d80b00'
<font color=brown>原因:</font> 在新頁面使用了NSMutableAttributedString轧飞,使用方式導(dǎo)致了崩潰衅鹿,目前無法解釋,使用方法如下:
NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:prodNameStr]; [attriString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.0] range:NSMakeRange(2, 2)]; [attriString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(2, 2)];
<font color=green>解決方案:</font>
NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:prodNameStr];
[attriString setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12.0], NSForegroundColorAttributeName:ColorWithHexString(GJS_COLOR_TEXT_GRAY)} range:NSMakeRange(prodNameStr.length - time.length, time.length)];`