Skip to content

Commit fe884a3

Browse files
committed
Initial version complete - iOS verified
1 parent 7da36e3 commit fe884a3

5 files changed

Lines changed: 44 additions & 16 deletions

File tree

ios/App/App.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@
345345
buildSettings = {
346346
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
347347
CODE_SIGN_STYLE = Automatic;
348+
DEVELOPMENT_TEAM = 9YN2HU59K8;
348349
INFOPLIST_FILE = App/Info.plist;
349350
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
350351
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -363,6 +364,7 @@
363364
buildSettings = {
364365
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
365366
CODE_SIGN_STYLE = Automatic;
367+
DEVELOPMENT_TEAM = 9YN2HU59K8;
366368
INFOPLIST_FILE = App/Info.plist;
367369
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
368370
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@ionic-native/splash-screen": "^5.0.0",
2727
"@ionic-native/status-bar": "^5.0.0",
2828
"@ionic/angular": "^4.7.1",
29+
"@ionic/pwa-elements": "^1.4.1",
2930
"core-js": "^2.5.4",
3031
"rxjs": "~6.5.1",
3132
"tslib": "^1.9.0",

src/app/services/photo.service.ts

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from '@angular/core';
2-
import { Plugins, CameraResultType, Capacitor, FilesystemDirectory } from '@capacitor/core';
2+
import { Plugins, CameraResultType, Capacitor, FilesystemDirectory, CameraPhoto, CameraSource } from '@capacitor/core';
33

44
const { Camera, Filesystem, Storage } = Plugins;
55

@@ -13,47 +13,59 @@ export class PhotoService {
1313
constructor() { }
1414

1515
async loadSaved() {
16+
// Retrieve cached photo array data
1617
const photos = await Storage.get({ key: this.PHOTO_STORAGE });
1718
this.photos = JSON.parse(photos.value) || [];
1819
}
1920

20-
// Use the device camera to take a photo.
21-
// Store the photo data into permanent file storage.
22-
// Store a reference to the photo in an array.
23-
async takePhoto() {
21+
/* Use the device camera to take a photo:
22+
// https://capacitor.ionicframework.com/docs/apis/camera
23+
24+
// Store the photo data into permanent file storage:
25+
// https://capacitor.ionicframework.com/docs/apis/filesystem
26+
27+
// Store a reference to all photo filepaths using Storage API:
28+
// https://capacitor.ionicframework.com/docs/apis/storage
29+
*/
30+
public async takePhoto() {
2431
// Take a photo
2532
const capturedPhoto = await Camera.getPhoto({
26-
resultType: CameraResultType.Uri
33+
resultType: CameraResultType.Uri, // file-based data; provides best performance
34+
source: CameraSource.Camera, // automatically take a new photo with the camera
35+
quality: 100 // highest quality (0 to 100)
2736
});
2837

2938
const savedImageFile = await this.savePicture(capturedPhoto);
3039

40+
// Add new photo to Photos array
3141
this.photos.unshift({
3242
filepath: savedImageFile,
3343
webviewPath: Capacitor.convertFileSrc(savedImageFile)
3444
});
3545

3646
// Cache all photo data for future retrieval
37-
//this.storage.set(this.PHOTO_STORAGE, this.photos);
47+
Storage.set({
48+
key: this.PHOTO_STORAGE,
49+
value: JSON.stringify(this.photos)
50+
});
3851
}
3952

4053
// Save picture to file on device
41-
async savePicture(cameraImage) {
54+
private async savePicture(cameraPhoto: CameraPhoto) {
4255
// Read the file into its base64 version
4356
const readFile = await Filesystem.readFile({
44-
path: cameraImage
57+
path: cameraPhoto.path
4558
});
4659

4760
// Write the file to the data directory (instead of temp storage)
4861
const fileName = new Date().getTime() + '.jpeg';
49-
5062
await Filesystem.writeFile({
5163
path: fileName,
5264
data: readFile.data,
5365
directory: FilesystemDirectory.Data
5466
});
5567

56-
// Get the full filepath
68+
// Get the new, complete filepath
5769
const fileUri = await Filesystem.getUri({
5870
directory: FilesystemDirectory.Data,
5971
path: fileName
@@ -63,14 +75,18 @@ export class PhotoService {
6375
}
6476

6577
// Delete picture by removing it from reference data and the filesystem
66-
async deletePicture(photo, position) {
67-
// Remove from our Photos reference data array
78+
public async deletePicture(photo: Photo, position: number) {
79+
// Remove this photo from the Photos reference data array
6880
this.photos.splice(position, 1);
69-
//await this.storage.set(PHOTO_STORAGE, this.photos);
7081

71-
// delete photo file
72-
const filename = photo.filepath.substr(photo.filepath.lastIndexOf('/') + 1);
82+
// Update photos array cache by overwriting the existing photo array
83+
Storage.set({
84+
key: this.PHOTO_STORAGE,
85+
value: JSON.stringify(this.photos)
86+
});
7387

88+
// delete photo file from filesystem
89+
const filename = photo.filepath.substr(photo.filepath.lastIndexOf('/') + 1);
7490
await Filesystem.deleteFile({
7591
path: filename,
7692
directory: FilesystemDirectory.Data

src/main.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
33

44
import { AppModule } from './app/app.module';
55
import { environment } from './environments/environment';
6+
import { defineCustomElements } from '@ionic/pwa-elements/loader';
67

78
if (environment.production) {
89
enableProdMode();
910
}
1011

1112
platformBrowserDynamic().bootstrapModule(AppModule)
1213
.catch(err => console.log(err));
14+
15+
// Call the element loader after the platform has been bootstrapped
16+
defineCustomElements(window);

0 commit comments

Comments
 (0)