實(shí)現(xiàn)ionic項(xiàng)目集成,更新對應(yīng)一個key對應(yīng)一個模塊
1、找到CodePushDeploymentKey獲取使用代碼位置,修改為可變。? ?
#pragma mark - 重寫父類創(chuàng)建方法,替換從config.xml中獲取的數(shù)據(jù)改為可變
- (UIView*) newCordovaViewWithFrame:(CGRect)bounds
{
? ? //self.codePushKey :類創(chuàng)建傳進(jìn)來的可變key
? ? if (self.codePushKey) {
? ? ? ? self.settings[@"codepushdeploymentkey"] = self.codePushKey;
? ? }
? ? return [super newCordovaViewWithFrame:bounds];
}
2、找到熱更新的路徑設(shè)置為可變。(本人實(shí)現(xiàn):用這個NSUserDefaults的方式將可變的CodePushDeploymentKey 替換 (導(dǎo)入的文件中拼死的路徑名)@"NoCloud")
@property (nonatomic, strong) NSString * codePushKey;
-(void)setCodePushKey:(NSString*)codePushKey{
? ? _codePushKey= codePushKey;
? ? [[NSUserDefaults standardUserDefaults] setObject:codePushKey forKey:@"ZXVariableFilename"];
? ? //將ionic手動導(dǎo)入的更新路徑不變的 @"NoCloud" 替換為可變的 [[NSUserDefaults standardUserDefaults] objectForKey:@"ZXVariableFilename"]
}
-->
3、 ?config.xml 中加入
? ? ?<preference name="WKInternalConnectionsOnly" value="false" />
? ? <preference name="UseScheme" value="true" />
//設(shè)置這兩,cordova的wkwebview才可以實(shí)現(xiàn)多份
注:Codova項(xiàng)目通過cocoapods集成。(可參考:http://www.itdecent.cn/p/4089106b93d1)
總結(jié):
1、newCordovaViewWithFrame:試圖初始化的地方,可以在這里修改或增加config.xml文件配置。如:self.settings[@"codepushdeploymentkey"] = self.codePushKey;
2、congfig.xml文件,配置項(xiàng)部分說明:
? ? ? ?a、WKInternalConnectionsOnly:默認(rèn)是Yes。當(dāng)為Yes,ionic頁面返回再進(jìn)入會報錯,只有殺死項(xiàng)目在進(jìn)(或者整個app就是一個wkwebview模塊就可以使用默認(rèn))
? ? ? ?b、UseScheme:默認(rèn)是No。當(dāng)為No,ionic頁面初始化 & key不同,ionic始終跳入第一更新內(nèi)容的ionic頁面
? ? ? ?c、CodePushDeploymentKey:ionic默認(rèn)key設(shè)置
? ? ? ?d、CordovaDefaultWebViewEngine:當(dāng)沒有配置CordovaWebViewEngine,默認(rèn)為CDVUIWebViewEngine(原生UIWebview)
? ? ? ?f、CordovaWebViewEngine:沒有默認(rèn),配置這個為CDVWKWebViewEngine(ionic會使用wkwebview),當(dāng)配置了此參數(shù),忽略CordovaDefaultWebViewEngine
? ? ?
3、@"NoCloud" :ionic所有文件中,通過這個可以找到所有更新,下載,刪除的ionci對應(yīng)路徑。
4、網(wǎng)上是能找到找到好多ionc相關(guān)的,重要的一個都沒怎么找到,感覺都是要自己摸索,好...坑...
附上繼承案例:
.h
#import
#import
#import
@interfaceApplyIonicWebVC :CDVViewController
@property (nonatomic, strong) NSString * codePushKey;
@end
@interfaceApplyIonicWebDelegate :CDVCommandDelegateImpl
@end
@interfaceApplyIonicWebQueue :CDVCommandQueue
@end
.m
/*使用? (備注:屬性不設(shè)置默認(rèn)使用 wwwFolderName:www、startPage:index.html)
?ApplyIonicWebVC *vc = [ApplyIonicWebVC new];
?vc.codePushKey = @"xxxxx";//xxxxx代表更新的CodePushDeploymentKey
?[self.navigationController pushViewController:vc animated:YES];
?*/
#import "ApplyIonicWebVC.h"
#import "CDVConfigParser.h"
@interface ApplyIonicWebVC ()
@end
@implementationApplyIonicWebVC
-(void)setCodePushKey:(NSString*)codePushKey{
? ? _codePushKey= codePushKey;
? ? [[NSUserDefaults standardUserDefaults] setObject:codePushKey forKey:@"ZXVariableFilename"];
? ? //將ionic手動導(dǎo)入的更新路徑不變的 @"NoCloud" 替換為可變的 [[NSUserDefaults standardUserDefaults] objectForKey:@"ZXVariableFilename"]
}
#pragma mark - 重寫父類創(chuàng)建方法,替換從config.xml中獲取的數(shù)據(jù)改為可變
- (UIView*) newCordovaViewWithFrame:(CGRect)bounds
{
? ? //self.codePushKey :類創(chuàng)建傳進(jìn)來的可變key
? ? if (self.codePushKey) {
? ? ? ? self.settings[@"codepushdeploymentkey"] = self.codePushKey;
? ? }
?? ?return [super newCordovaViewWithFrame:bounds];
}
@end
@implementationApplyIonicWebDelegate
@end
@implementationApplyIonicWebQueue
@end