前言
開發做筆記是好習慣,總結分享是鞏固記憶。
遇到問題,思考其背后的原因、原理。
AFNetworking
- 1、progress回調block,不在主線程;
- 2、iPhone4+iOS7,progress回調異常;
AFNetworking 處理請求是在后臺線程,所以block回調的時候最好加一個dispatch。
我們默認把所有的網絡請求在后臺線程進行,但是回調的時候dispatch到主線程。
關閉鍵盤
在任意界面,dismiss鍵盤。(蘋果的響應鏈設計)
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
蘋果的解釋:
The object to receive the action message. If target is nil, the app sends the message to the first responder, from whence it progresses up the responder chain until it is handled.
類似AS3的冒泡查找響應者。
Provisioning Profile
iOS Team Provisioning Profile是第一次使用Xcode添加設備時,Xcode自動生成的,它包含了Xcode生成的一個Wildcard App ID(*,匹配所有應用程序),賬戶里面所有的Devices和所有Development Certificates,如下圖所示。因此,team中的所有成員都可以使用這個iOS Team Provisioning Profile在team中的所有設備上調試所有的應用程序。并且當有新設備添加進來時,Xcode會更新這個文件。
開發者QA
蘋果的安全認證體系:如何用證書、APPID、profile來驗證開發者身份、IPA包正確性?
基本要求:保證設備的安全;驗證開發者身份。
UILongpressGestureRecognizer
給view添加UILongpressGestureRecognizer,
觸發長按之后,UILongpressGestureRecognizer的識別范圍也會包含其superView;同時,觸發長按之后,UIButton的高亮狀態就會消失。
這是因為識別為長按之后就會將UIButton的touch cancel掉,UIButton不會給長按設置highlighted狀態。
在begin后設置UIButton的selected為YES,移出UIButton后設置為NO,這樣就可以實現長按點擊的效果。
- (void)longPressAction:(UILongPressGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateBegan) {
bLongPress = YES;
[self sendAction];
_dodgersBtn.selected = YES;
}
else if (recognizer.state == UIGestureRecognizerStateEnded) {
bLongPress = NO;
_dodgersBtn.selected = NO;
}
}
[_dodgersBtn setBackgroundImage:normalDodgerImg forState:UIControlStateNormal];
[_dodgersBtn setBackgroundImage:focusDodgerImg forState:UIControlStateSelected];
[_dodgersBtn setBackgroundImage:focusDodgerImg forState:UIControlStateHighlighted];
//三個按鈕狀態,都得設置。
Xcode
問題1:Your build settings specify a provisioning profile with the UUID “”,
however, no such provisioning profile was found
通常來說是因為項目中引用了一個無效的PROVISIONING_PROFILE。按command+F,在這個文件中查找“PROVISIONING_PROFILE"。查找對應UUID的profile是否存在其他地方的引用。
問題2:Xcode 7.2 Organizer無限菊花、無限加載、卡頓如何解決?
1、證書相關:Preferences -> Accounts -> Account -> ViewDetails
2、文件過多:刪除下列文件夾中無用文件
/Users/user/Library/Developer/Xcode/Products
/Users/loyinglin/Library/Developer/Xcode
問題3:nib but the view outlet was not set
nib文件 -> File's Owner -> command+4 >查看 Class 屬性
檢查Files's Owner的view是否有關聯
PS:不關聯,Xcode不知道是誰的類,此時無法進行合適的編譯。(Xcode在編譯的時候就會把xib處理成一個中間文件(xml=>nib),以便于在運行時加載)
問題4:A valid provisioning profile for this executable was not found
檢查 Project 和 Target 的Code Signing Identity 與Provisioning Profile 設置是否一致;Provisioning Profile會告訴Xcode哪些證書是允許簽名。(見上面的圖)
問題5:debug時如何查看崩潰地址?
如果是異常引起的Crash,可以用下面的方法。
通用的解決方案是在命令行里打bt,會出堆棧。
Category
用Category來分離業務時,在Category使用了ActionSheet。如果對應的ViewController也實現了- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
,邏輯就會存在問題。
category盡量不存在和原ViewController一致的方法。所以希望對category按照業務進行聚合,避免沖突。
RunLoop
RunLoop用來系統喚醒休眠線程,處理異步的事件,比如說url請求。
默認performSelectorOnMainThread:withObject:waitUntilDone:
是在默認的Runloop mode,如果runloop處于其他mode(比如說tracking mode),它會等待runloop切換回默認的mode。
-performSelectorOnMainThread:withObject:waitUntilDone:modes:
可以選擇添加到的runloop mode。
dispatch_async(dispatch_get_main_queue(), ^{ })
會盡可能快的去執行block,而不管modes。
每個線程都會關聯到不同的RunLoop,線程的Runloop可以工作在不同的modes。
RunLoop博客
總結
寫于2018年7月,對文章進行一期整理,把知識點挖得更深入。