diff --git a/ios/App/App/config.xml b/ios/App/App/config.xml index 0e150fb39..e8e0ad6db 100644 --- a/ios/App/App/config.xml +++ b/ios/App/App/config.xml @@ -2,6 +2,10 @@ + + + + diff --git a/ios/App/Podfile b/ios/App/Podfile index adfe46e8e..09f7e565d 100644 --- a/ios/App/Podfile +++ b/ios/App/Podfile @@ -9,8 +9,11 @@ install! 'cocoapods', :disable_input_output_paths => true def capacitor_pods pod 'Capacitor', :path => '../../node_modules/@capacitor/ios' pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios' + pod 'CapacitorApp', :path => '..\..\node_modules\@capacitor\app' + pod 'CapacitorCamera', :path => '..\..\node_modules\@capacitor\camera' pod 'CapacitorFilesystem', :path => '..\..\node_modules\@capacitor\filesystem' pod 'CapacitorHaptics', :path => '..\..\node_modules\@capacitor\haptics' + pod 'CapacitorPushNotifications', :path => '..\..\node_modules\@capacitor\push-notifications' pod 'CapacitorVoiceRecorder', :path => '..\..\node_modules\capacitor-voice-recorder' pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins' pod 'CordovaPluginsResources', :path => '../capacitor-cordova-ios-plugins' diff --git a/src/app/services/functions/file.service.ts b/src/app/services/functions/file.service.ts index 55483dc5c..a7014bb73 100644 --- a/src/app/services/functions/file.service.ts +++ b/src/app/services/functions/file.service.ts @@ -2,14 +2,14 @@ import { Injectable } from '@angular/core'; import { FileLoaderService } from '../file/file-loader.service'; import { FileToBase64Service } from '../file/file-to-base64.service'; import { InAppBrowser } from '@ionic-native/in-app-browser/ngx'; -//Cordova -import { Camera, CameraOptions } from '@ionic-native/camera/ngx'; + import { ChatService } from '../chat.service'; import { ModalController } from '@ionic/angular'; import { SearchPage } from 'src/app/pages/search/search.page'; import { SearchList } from 'src/app/models/search-document'; import { ProcessesService } from '../processes.service'; import { ToastService } from '../toast.service'; +import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera'; @Injectable({ providedIn: 'root' @@ -22,9 +22,9 @@ export class FileService { showLoader: boolean; files: Set; + photos: any[] = []; constructor( - private camera: Camera, private fileLoaderService: FileLoaderService, private fileToBase64Service: FileToBase64Service, private iab: InAppBrowser, @@ -34,26 +34,25 @@ export class FileService { private toastService: ToastService, ) { } - takePicture() { - const options: CameraOptions = { - quality: 50, - destinationType: this.camera.DestinationType.DATA_URL, - encodingType: this.camera.EncodingType.JPEG, - mediaType: this.camera.MediaType.PICTURE, - targetWidth: 720, - targetHeight: 720, - } + async takePicture() { + const capturedImage = await Camera.getPhoto({ + quality: 90, + // allowEditing: true, + resultType: CameraResultType.Uri, + source: CameraSource.Camera - this.camera.getPicture(options).then((imageData) => { - // imageData is either a base64 encoded string or a file URI - // If it's base64 (DATA_URL): m - //let base64Image = 'data:image/jpeg;base64,' + imageData; - - this.capturedImage = 'data:image/png;base64,'+imageData; - this.capturedImageTitle = new Date().getTime() + '.jpeg'; - }, (err) => { - /* console.log(err); */ }); + const response = await fetch(capturedImage.webPath!); + const blob = await response.blob(); + + this.photos.unshift({ + filepath: "soon...", + webviewPath: capturedImage.webPath + }); + + this.capturedImage = await this.convertBlobToBase64(blob); + this.capturedImageTitle = new Date().getTime() + '.jpeg'; + let data = { image:this.capturedImage, name: this.capturedImageTitle @@ -62,6 +61,15 @@ export class FileService { return data; } + convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => { + const reader = new FileReader; + reader.onerror = reject; + reader.onload = () => { + resolve(reader.result); + }; + reader.readAsDataURL(blob); + }); + loadPicture() { const input = this.fileLoaderService.createInput({ accept: ['image/apng', 'image/jpeg', 'image/png'] @@ -85,19 +93,24 @@ export class FileService { }; } - addCameraPictureToChat(roomId){ + async addCameraPictureToChat(roomId){ - const options: CameraOptions = { - quality: 50, - destinationType: this.camera.DestinationType.DATA_URL, - encodingType: this.camera.EncodingType.JPEG, - mediaType: this.camera.MediaType.PICTURE, - targetWidth: 720, - targetHeight: 720, - } + const capturedImage = await Camera.getPhoto({ + quality: 90, + // allowEditing: true, + resultType: CameraResultType.Uri, + source: CameraSource.Camera - this.camera.getPicture(options).then((imageData) => { - this.capturedImage = 'data:image/png;base64,'+imageData; + }); + const response = await fetch(capturedImage.webPath!); + const blob = await response.blob(); + + this.photos.unshift({ + filepath: "soon...", + webviewPath: capturedImage.webPath + }); + + this.capturedImage = await this.convertBlobToBase64(blob); this.capturedImageTitle = new Date().getTime() + '.jpeg'; let body = { @@ -121,29 +134,26 @@ export class FileService { this.toastService.badRequest("Não foi possível adicionar a fotografia!"); }); - }, (err) => { - this.toastService.badRequest("Não foi possível adicionar a fotografia!"); - }); - } - addPictureToChatMobile(roomId) { - alert('Here') + async addPictureToChatMobile(roomId) { - const options: CameraOptions = { + const capturedImage = await Camera.getPhoto({ quality: 90, - sourceType: this.camera.PictureSourceType.PHOTOLIBRARY, - destinationType: this.camera.DestinationType.DATA_URL, - encodingType: this.camera.EncodingType.JPEG, - mediaType: this.camera.MediaType.PICTURE, - targetWidth: 720, - targetHeight: 720, - correctOrientation: true - } + // allowEditing: true, + resultType: CameraResultType.Uri, + source: CameraSource.Camera - this.camera.getPicture(options).then((imageData) => { - let base64Image = 'data:image/jpeg;base64,' + imageData; - this.capturedImage = imageData; + }); + const response = await fetch(capturedImage.webPath!); + const blob = await response.blob(); + + this.photos.unshift({ + filepath: "soon...", + webviewPath: capturedImage.webPath + }); + + this.capturedImage = await this.convertBlobToBase64(blob); this.capturedImageTitle = new Date().getTime() + '.jpeg'; //const loader = this.toastService.loading(); @@ -161,21 +171,12 @@ export class FileService { }] } } - - console.log(this.capturedImage) - this.chatService.sendMessage(body).subscribe(res=> { //loader.remove(); //console.log(res); },(error) => { //loader.remove(); }); - - - }, (err) => { - //console.log(err); - }); - } addPictureToChat(roomId) { diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 1fff2ddf0..9f77e4286 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -3,7 +3,7 @@
- {{users.name}}11 + {{users.name}}
- + diff --git a/src/app/shared/publication/new-publication/new-publication.page.html b/src/app/shared/publication/new-publication/new-publication.page.html index 00cc16305..8b2e040d5 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.html +++ b/src/app/shared/publication/new-publication/new-publication.page.html @@ -27,7 +27,6 @@
-
image @@ -84,7 +83,6 @@ -