一:資源包問題及組件iconfont使用
1柬焕、第一種podspec資源的配置
s.resources = 'FN_FNYongNeng_Login/Assets/*'
資源讀取方式
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"FN_FNYongNeng_Login" ofType:@"ttf"];
UIImage *login_user = [UIImage imageWithIconFontComponent:FNIconFontComponentTTFMake(@"\U0000e60e", 24, HexRGB(0x333333), path)];
2、第二種podspec資源的配置
s.resource_bundles = {
'FN_FNYongNeng_Login' => ['FN_FNYongNeng_Login/Assets/*']
}
資源讀取方式
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"FN_FNYongNeng_Login" ofType:@"ttf" inDirectory:@"FN_FNYongNeng_Login.bundle"];
UIImage *login_user = [UIImage imageWithIconFontComponent:FNIconFontComponentTTFMake(@"\U0000e60e", 24, HexRGB(0x333333), path)];
二:組件的CTMediator入?yún)⒓俺鰠?/h3>
入?yún)⒓蚩尽⒊鰠⑷荖SDictionary
/**
創(chuàng)建登錄
@param params 入?yún)? @param callBackBlock block回調(diào)
@return 日歷控制器
*/
- (UIViewController *)CTMediator_FNYongNengLoginVC:(NSDictionary *)params callBackBlock:(void (^)(NSDictionary *dic))callBackB
- (UIViewController *)CTMediator_FNYongNengLoginVC:(NSDictionary *)params callBackBlock:(void (^)(NSDictionary *dic))callBackBlock {
NSMutableDictionary *tmpParams = [NSMutableDictionary dictionary];
tmpParams[kFNLoginVC_LoginSuccessBlock] = callBackBlock;
UIViewController *viewController = [self performTarget:kCTMediatorTarget_FNLoginViewController
action:kCTMediatorAction_nativeFetchFNLoginViewController
params:tmpParams
shouldCacheTarget:NO];
if ([viewController isKindOfClass:[UIViewController class]]) {
// view controller 交付出去之后,可以由外界選擇是push還是present
return viewController;
} else {
// 這里處理異常場景,具體如何處理取決于產(chǎn)品
NSLog(@"%@ 未能實例化頁面", NSStringFromSelector(_cmd));
return [[UIViewController alloc] init];
}
}
三:組件使用podspec配置層級目錄
組件內(nèi)部文件默認(rèn)是不在文件夾下的敛惊,即使在本地Development Pods中看到了文件夾膊毁,用戶通過pod引入時還是看不到胀莹。要想實現(xiàn)實體文件夾,需要修改subspec的文件目錄層次婚温。
根目錄是s描焰,使用s.subspec設(shè)置子目錄,這里設(shè)置子目錄為ss
s.source_files = 'FN_FNFanNeng_DataSummary/Classes/*.*'
s.subspec 'Mediator' do |ss|
ss.source_files = 'FN_FNFanNeng_DataSummary/Classes/Mediator/*.*'
end
s.subspec 'MonthlyData' do |ss|
ss.source_files = 'FN_FNFanNeng_DataSummary/Classes/MonthlyData/*.*'
end
s.subspec 'Views' do |ss|
ss.source_files = 'FN_FNFanNeng_DataSummary/Classes/Views/*.*'
end
s.resource = 'FN_FNFanNeng_DataSummary/Assets/*'
注意:需要把s.source_files最后改為 /*.*
四:Bundle中的圖片命名
Bundle中的圖片命名:如果圖片命名為640x1136栅螟,則真機無法加載荆秦,模擬器無影響,需改為640*1136
五:保持Podfile中的iOS版本和podspec版本統(tǒng)一
Podfile文件中 :
platform :ios, ‘9.0’
Podspec文件中:
s.ios.deployment_target = '9.0'
要始終保持這兩個版本一致力图,不然pod install會出錯步绸。
六:include of non-modular header inside framework module
在封裝振動采集VibrationAcquistion框架時,更新到 Cocoapods 的時候出現(xiàn)一個錯誤吃媒,核心語句是 error: include of non-modular header inside framework module
瓤介,在使用 Swift 的庫時會出現(xiàn)這個問題,把 Target 下 Build Settings
中 Allow Non-modular includes in Framework Modules
設(shè)為 Yes 就解決了晓折。
七:Bitcode問題
如果組件內(nèi)直接或間接接入EZOpenSDKFramework惑朦,會引起以下報錯:
ld: '~/Pods/EZOpenSDK/dist/EZOpenSDK/dynamicSDK/EZOpenSDKFramework.framework/EZOpenSDKFramework' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file '~/Pods/EZOpenSDK/dist/EZOpenSDK/dynamicSDK/EZOpenSDKFramework.framework/EZOpenSDKFramework' for architecture arm64
這是因為EZOpenSDKFramework是關(guān)閉Bitcode的,所以我們?nèi)绻眠@個Framework的話漓概,就必須把項目的Bitcode關(guān)閉漾月。可以在Podfile中添加以下語句胃珍,把所有Pod中的Bitcode都關(guān)閉梁肿。
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
八:組件中引用WKWebView的問題
(1)如果某個VC中引用了WKWebView,在iOS9系統(tǒng)下點擊返回按鈕返回上級頁面的時候會造成crash.
-[FNWebViewController retain]: message sent to deallocated instance 0x7fa1974a33f0
因為 WKWebView 的 UIScrollView 代理惹的禍觅彰,因為我需要實時監(jiān)聽網(wǎng)頁的滾動區(qū)域來處理一些事情吩蔑,所以我把 WKWebView.scrollView.delegate 設(shè)置為當(dāng)前控制器。
只要在VC的dealloc方法中把delegate置為nil就好了填抬。
- (void)dealloc {
self.webView.scrollView.delegate = nil; // Fix iOS9 crash.
}
(2)如果引用WKWebView的VC中還有大標(biāo)題烛芬,那么在iOS12上會出現(xiàn)偏移量的問題。WKWebView會默認(rèn)有一個偏移量,最終展示為小標(biāo)題+Webview赘娄。
解決方式:需要在webView加載完畢后重置一下偏移量
-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
[FNProgressHUD dismissForView:self.view];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//數(shù)據(jù)加載完成再設(shè)置代理仆潮,避免標(biāo)題閃一下
webView.scrollView.delegate = self;
//重新設(shè)置一下contentoffset,修復(fù)WKWebView在iOS12上導(dǎo)航欄偏移的問題
CGFloat bigTitleHeight = self.dynamicNavView.bigTitleView.frame.size.height;
[webView.scrollView setContentOffset:CGPointMake(0, - bigTitleHeight) animated:NO];
});
}
webView.scrollView.delegate = self
也要放到didFinishNavigation
中遣臼,避免大標(biāo)題會閃動