我正在开发一个Ionic/Cordova跨平台应用程序,并且在调试方面遇到了一些困难。当然,可以通过运行ionic serve然后使用浏览器开发人员工具直接从浏览器完成调试,但某些行为仅发生在真实设备上。
我遇到一个有趣的问题:我正在开发一个离子应用程序,用于cordova-plugin-file存储图像。生成的路径(格式为 file:///... 的 URI)与更多信息一起存储在 SQLite DB 中。当我安装该应用程序并使用它时,一切都很完美。但是,如果我更新(或重新安装)应用程序,则不再找到旧图像,而新添加的图像则可以完美工作。
我首先怀疑图像文件在更新时被删除,但我检查了目录的内容,文件仍然存在。(仅供参考:我用来file.dataDirectory/scans/放置我的文件)。
然后我想也许我可以解决加载到img src加载了 的 base64 blob中的问题cordova.file.readAsUrl(),但 cordova.file 也找不到该文件(我坚持认为,文件在那里,我用 XCode 检查过)。
因此,我进一步检查cordova.file,它只找到上次应用程序安装后添加的文件,但较旧的文件仍然存在于目录中。
这是我的代码:
private getImgSrcFromDocument(doc: Document): any {
const uri = doc.fileName;
const src = this.webView.convertFileSrc(uri);
const sanitized = this.sanitizer.bypassSecurityTrustUrl(src);
console.log({uri, src, sanitized});
return sanitized;
}
Run Code Online (Sandbox Code Playgroud)
<img class="document_thumbnail" [src]="getImgSrcFromDocument(doc)">
Run Code Online (Sandbox Code Playgroud)
我已经检查过了,但不是我的情况。
顺便说一下,同样的代码在 Android 上运行得很好。
知道可能是什么问题吗?提前致谢!
Android studio 不断构建第一个 Android 项目并将其安装到设备中。
我努力了
npx cap sync
npx cap copy android
Run Code Online (Sandbox Code Playgroud)
甚至删除/android文件夹并重新添加。该项目仍然是我第一次添加到android studio时的情况。我尝试过“Gradle 同步”和“无效缓存/重新启动”仍然没有成功。
我已将项目资源图标和启动画面更新为自定义图标,但 Android 项目仍然使用电容器默认图标和启动画面。以前有人遇到过这个问题吗?
我无法在 Ionic 5 中实现 canDeactivate 防护。以下是我的代码。
模型.ts
export interface isDeactivatable {
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
}
Run Code Online (Sandbox Code Playgroud)
离开页面.guard.ts
export class LeavePageGuard implements CanDeactivate<isDeactivatable>{
canDeactivate(
component: isDeactivatable
): Observable<boolean> | Promise<boolean> | boolean {
console.log('LeavePageGuard');
return component.canDeactivate();
}
}
Run Code Online (Sandbox Code Playgroud)
测试页.ts
export class TestPage implements OnInit, isDeactivatable{
canDeactivate(): Observable<boolean> | Promise<boolean> | boolean {
console.log('canDeactivate in TestPage');
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
本地路由.Module.ts
const routes: Routes = [
{
path: '',
component: HomePage,
children:[
{
path: 'test',
loadChildren: () => …Run Code Online (Sandbox Code Playgroud) lazy-loading ionic-framework angular-route-guards candeactivate ionic5
每个 Ionic 项目都有一个项目配置文件ionic.config.json,您可以在其中配置应用程序的人类可读名称:
{
// The human-readable name of the app.
"name": "My App",
// The project type of the app. The CLI uses this value to determine which
// commands and command options are available, what to output for help
// documentation, and what to use for web asset builds and the dev server.
"type": "angular",
// The App ID for Ionic Appflow.
"id": "abc123",
// Configuration object for integrations such as Cordova and Capacitor.
"integrations": { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我尝试过的 Ionic 5 构建网络应用程序:
ionic cordova build browser --prod --release
Run Code Online (Sandbox Code Playgroud)
和
ionic serve --prod
Run Code Online (Sandbox Code Playgroud)
都失败并出现如下错误:
1. If 'ion-header' is an Angular component, then verify that it is part of this module.
2. If 'ion-header' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
1. If 'ion-icon' is an Angular component, then verify that it is part of this module.
2. If 'ion-icon' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the'@NgModule.schemas' of …Run Code Online (Sandbox Code Playgroud) 尝试使用电话号码填充简单的无线电组列表时
无法绑定到“ngForOf”,因为它不是“ion-item”的已知属性。
问题与 Angular 9 有关。可能的解决方案表明需要就位 BrowserModule 和 Common 模块。我想我明白了。然而,错误仍然存在。
离子信息:
Ionic CLI : 5.4.13
Ionic Framework : @ionic/angular 5.1.0
@angular-devkit/build-angular : 0.901.4
@angular-devkit/schematics : 9.1.4
@angular/cli : 9.1.4
@ionic/angular-toolkit : 2.2.0
Capacitor:
Capacitor CLI : 2.0.2
@capacitor/core : 2.0.2
Cordova:
Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.1.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 6 other plugins)
Utility:
cordova-res (update available: 0.15.0) : 0.6.0
native-run (update available: 1.0.0) : 0.2.8
Run Code Online (Sandbox Code Playgroud)
添加编号.page.ts
import { …Run Code Online (Sandbox Code Playgroud) 我知道要在嵌套对象中使用Firestore FieldValue increment函数,我需要在update方法中提及完整的路径。我的 Ionic 5 项目的 main 方法采用对象字段的名称。以下是我尝试使用它的方法
updateCounter(attr: string){
Way1:
let obj = {};
obj[attr] = firebase.firestore.FieldValue.increment(1); //This is working
obj.count[attr] = firebase.firestore.FieldValue.increment(1); //This is not working. Value is always 1
this.afs.doc('path').update(obj);
Way2:
this.afs.doc('path').update({
'count.${attr}': firebase.firestore.FieldValue.increment(1); //Creating a field called '${attr}' and not replacing the value;
});
Way3:
this.afs.doc('path').update({
`count.${attr}`: firebase.firestore.FieldValue.increment(1); //Error as '``' value not accepted in the function
});
}
Run Code Online (Sandbox Code Playgroud) 当我尝试单击 Azure B2C 登录页面上的 google 登录时,它会将我重定向到另一个页面,并显示错误 403 disallowed_useragent。
这是我到目前为止所尝试的:
添加尝试添加文档overrideUserAgent中提到的内容。将这一行添加到 Capacitor.config.json 的根部
"overrideUserAgent": "Mozilla/5.0 Google"
Run Code Online (Sandbox Code Playgroud)
我还尝试添加 UserAgent插件 我在应用程序组件中添加此行来设置用户代理
this.userAgent.set('Mozilla/5.0 Google')
.then((res: any) => console.log('UserAgent test' + res))
.catch((error: any) => console.error(error));
Run Code Online (Sandbox Code Playgroud)
最后我还在 config.xml 中添加了这一行
<preference name="OverrideUserAgent" value="Mozilla/5.0 Google" />
Run Code Online (Sandbox Code Playgroud)
当我调试 inAppBrowser 控制台日志时,这些解决方案中的任何一个都有效,我在请求标头中看到此结果
user-agent: Mozilla/5.0 (Linux; Android 11; sdk_gphone_x86 Build/RPB1.200504.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.44 Mobile Safari/537.36
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。
我有一个 Ionic 应用程序,使用离子菜单来打开汉堡菜单。但是,我不想让背景位于右侧,如屏幕截图所示:
我想要的是这个(没有背景):
离子菜单:
<ion-menu side="start" type="push" menuId="first" contentId="main" class="burger-menu">...</ion-menu>
Run Code Online (Sandbox Code Playgroud)
我已经尝试过 CSS 中的所有内容:
.burger-menu {
// Doesn't work
--backdrop: none !important;
backdrop-filter: none !important;
}
// Doesn't work
ion-menu#backdrop {
display: none !important;
}
// Doesn't work
ion-menu > ion-backdrop {
display: none !important;
}
// Doesn't work
ion-backdrop.menu-backdrop {
display: none !important;
}
// Doesn't work
:host(.menu-type-push) .show-backdrop {
display: none !important;
}
Run Code Online (Sandbox Code Playgroud)
但它们似乎都不起作用。
ionic-framework ×10
capacitor ×3
ionic4 ×3
angular ×2
cordova ×2
ionic5 ×2
ios ×2
javascript ×2
android ×1
azure-ad-b2c ×1
debugging ×1
lazy-loading ×1
ngfor ×1