【发布时间】:2020-11-30 14:28:51
【问题描述】:
我正在尝试将图像从 WhatsApp 共享到我的应用程序。 每当我将 WhatsApp 中的媒体项目共享到我的应用程序时,它都会点击 webmanifest 文件并以 /nav/emergencyRegister 路由为目标。 我确信它会到达目标路线,因为当我从 WhatsApp 共享图像时,它会在前端打开相同的路线。
这是我的 manifest.webmanifest 文件中的代码。
{
"name": "Apoms",
"short_name": "Apoms",
"theme_color": "#1976d2",
"background_color": "#fafafa",
"display": "standalone",
"scope": "/",
"start_url": "/",
"gcm_sender_id": "275309609166",
"share_target": {
"action": "/nav/emergency-register",
"method": "POST",
"enctype": "multipart/form-data",
"params": {
"title": "name",
"text": "description",
"url": "link",
"files": [
{
"name": "images",
"accept": "image/*"
},
{
"name": "videos",
"accept": "video/*"
}
]
}
}
但是在 EmergencyRegisterComponent.ts 文件中,我不知道如何访问应该在路由参数中的图像。
这是我在紧急注册页面.component.ts 文件中的代码。
import { Component, OnInit } from '@angular/core';
import { PrintTemplateService } from '../../print-templates/services/print-template.service';
import { CaseService } from '../services/case.service';
import { EmergencyRegisterTabBarService } from '../services/emergency-register-tab-bar.service';
import { Router, ActivatedRoute } from '@angular/router';
@Component({
// tslint:disable-next-line:component-selector
selector: 'emergency-register-page',
templateUrl: './emergency-register-page.component.html',
styleUrls: ['./emergency-register-page.component.scss'],
})
export class EmergencyRegisterPageComponent implements OnInit {
constructor(private printService: PrintTemplateService,
private route: ActivatedRoute,
private caseServie: CaseService,
private tabBar: EmergencyRegisterTabBarService) {}
ngOnInit() {
this.printService.initialisePrintTemplates();
// I printed the this.route and tried to find the image in there but failed.
// Also used params,querParams from route.
const data = this.route.snapshot.paramMap.get('files');
console.log(data);
}
}
我还尝试从here 扩展现有的服务工作者。 我创建了一个新的 service worker 文件 apoms-sw.js
importScripts('./ngsw-worker.js');
self.addEventListener('fetch', event=>{
console.log(event);
});
在我的 app.module.ts 中
@NgModule({
declarations: [AppComponent, ConfirmationDialog, TreatmentRecordComponent],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
MatDialogModule,
NavModule,
HttpClientModule,
MaterialModule,
ServiceWorkerModule.register('apoms-sw.js', { enabled: environment.production }),
AngularFireDatabaseModule,
AngularFireAuthModule,
AngularFireMessagingModule,
AngularFireStorageModule,
AngularFireModule.initializeApp(environment.firebase)
],
exports: [],
providers: [
DatePipe,
{ provide: HTTP_INTERCEPTORS, useClass: HttpConfigInterceptor, multi: true },
// { provide: LOCALE_ID, useValue: 'it-IT' },
{ provide: ErrorHandler, useClass: UIErrorHandler }
],
bootstrap: [AppComponent],
})
我可以看到文件在远程调试过程中被命中,但它没有触发 fetch 事件侦听器。 因此,如果有人能告诉我如何访问路线随附的图像。会很棒的。
【问题讨论】:
标签: angular typescript whatsapp