public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}
launchUrl = "http://localhost/";
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
}
这样热更新就可以正常工作了。
我继续做了点测试,又发现一个和 ionic icon 相关的问题,ionic 4 使用了 Fetch API 来请求 ionic icon 的 svg 资源,由于现在是使用 file schema 来指定资源路径,由于 Fetch API 不支持 file schema 所以就报错 Fetch API cannot load file:///xxx/www/svg/md-star.svg. URL scheme "file" is not supported. 我们得想办法来解决这个问题,一个办法替换 fetch 方法的实现,如:
在这些测试过程中,我还发现 cordova hot code push 更新时只做了版本字符是否相等的判断,这在服务器端的版本低于本地版本时,插件仍然会做更新,这是有问题的,我们需要严格这里的判断,让它只有在服务端的版本高于本地版本时才做更新。相关代码位于 UpdateLoaderWorker 的 run 方法中。
首先是提示 kernel headers not found for target kernel 的错误,也提示详细的错误信息位于 /var/log/vboxadd-setup.log,我们可以通过查看该错误日志来找到对应解决方法。于是尝试安装对应的内核头文件,命令为 yum install kernel-headers kernel-devel,之后执行 /sbin/rcvboxadd setup.
仍然提示 kernel headers not found for target kernel,通过 uname -r 和 rpm -q kernel-headers 发现版本不一致,于是重启系统选择最新的内核版本。
再次尝试安装,提示 Error building the module,查看错误日志提示需要安装 libelf-dev, libelf-devel or elfutils-libelf-devel ,CentOS 上只有 elfutils-libelf-devel ,安装之后再次安装 VirtualBox Guest Additions。
提示
123
ValueError: File context for /opt/VBoxGuestAdditions-6.0.14/other/mount.vboxsf already defined
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted
// Create a tag
$git tag <tagname>
// Push to repository
$git push origin master
升级 cordova plugin
现在暂时没有直接升级的命令,采用的是先卸载后安装新版本的方法。
如何创建 Cordova Plugin 对应的 Ionic Native
Creating Plugin Wrappers
123456789101112
// Navigate to ionic-native root path
$cd ionic-native
// Install dependencies first time
$npm install
// Create plugin wrapper
// When gulp installed locally
$npx gulp plugin:create -n PluginName
// When gulp installed globally
$gulp plugin:create -n PluginName
安装
12345
// You need to run npm run build in the ionic-native project, this will create a dist directory. The dist directory will contain a sub directory @ionic-native with all the packages compiled in there.
$npm run build
//Copy the package(s) you created/modified to your app's node_modules under the @ionic-native directory.
$cp -r dist/@ionic-native/plugin-name ../my-app/node_modules/@ionic-native/
// Import the plugin in a @NgModule and add it to the list of Providers.
// app.module.ts
import { APIClient } from '@ionic-native/api-client/ngx';
...
@NgModule({
...
providers: [
...
APIClient
...
]
...
})
export class AppModule { }
// After the plugin has been declared, it can be imported and injected like any other service:
// login.service.ts
import { APIClient } from '@ionic-native/api-client/ngx';
import { ServiceName } from '@ionic-native/api-client/ngx';
constructor(private apiClient: APIClient) { }
this.apiClient.get(ServiceName.Login, JSON.stringify(user))
.then((result: string) => {
console.log('api client login:', result);
//TODO: Parse server return json to UserExt object
const routePath = this.simulateLogin(username);
resolve(routePath);
})
.catch((error: string) => {
console.log('api client login error:', error);
reject(error);
});