nstudio / nstudio/nativescript-plugins

Callback on iOS returns no asset

Open
#42 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
55
Forks
42
Avg merge
49m
Merged PRs (30d)
1

Description

CameraPlus

Set saveToGallery to false.

When photoCapturedEvent is emitted, the event.data contains not a saved image, but just an empty object.

Cause:

in index.ios.js Line 490 ff MySwifty.prototype.savePhoto

var asset_1 = new ImageAsset(this._photoToSave);

fails. this._photoToSave is an iOS UIImage and it seems ImageAsset can't handle this.

Solution

Safe the image and then return it.

So I added this to the function:

if (isIOS) {

  const imageFolder = knownFolders.documents(); 
  const iosImage = UIImageJPEGRepresentation(this._photoToSave, 0.7);

  const result1 = NSFileManager.defaultManager.createFileAtPathContentsAttributes(imageFolder.path + "/cam_capture.jpg", iosImage, null);

  const asset = new ImageAsset(imageFolder.path + "/cam_capture.jpg");

   _this._owner.get().sendEvent(CameraPlus.photoCapturedEvent, asset);
   _this.resetPreview();

}

Of course, you can give the image a different name and save it at a different location.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in index.ios.js around line 490, in MySwifty.prototype.savePhoto, and inspect the saveToGallery=false path where photoCapturedEvent is emitted. Verify how the UIImage is converted to an ImageAsset; done means the event data contains the captured asset instead of an empty object.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, javascript
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.