Using SwiftUI's new ShareLink, with a photo. The Share sheet does not have save to album option. Does anyone know how could I get that option, because I need to save an image to the photo library.
As you can see on the screenshot below, it only has add to shared album option.
struct Photo: Transferable {
static var transferRepresentation: some TransferRepresentation {
ProxyRepresentation(\.image)
}
public var image: Image
public var caption: String
}
ShareLink(item: photo, preview: SharePreview(photo.caption, image: Image("miniIcon"))) { }
Solved. For whoever encountered this problem. You need to add photo library permission in the Info plist.
Related
I want to know if there is a place in ios devices where I can store video files in a way such that:
1) Users are not able to find video files outside the app.
2) No other app can read the video files.
3) Even jail-broken devices can't access the video files outside the app.
The only way I want these video files to be accessed is through the app only.
Please help me to know where to save the files.
First of all, take a look at link posted by #karthikeyan.
https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html
Choose the right 'SearchPathDomainMask'.
let documents = try! FileManager.default.url(for: .documentDirectory, in: .localDomainMask, appropriateFor: nil, create: false)
From Apple Library:
public struct SearchPathDomainMask : OptionSet {
public init(rawValue: UInt)
public static var userDomainMask: FileManager.SearchPathDomainMask { get }
// user's home directory --- place to install user's personal items (~)
public static var localDomainMask: FileManager.SearchPathDomainMask { get }
// local to the current machine --- place to install items available to everyone on this machine (/Library)
public static var networkDomainMask: FileManager.SearchPathDomainMask { get }
// publically available location in the local area network --- place to install items available on the network (/Network)
public static var systemDomainMask: FileManager.SearchPathDomainMask { get }
// provided by Apple, unmodifiable (/System)
public static var allDomainsMask: FileManager.SearchPathDomainMask { get }
// all domains: all of the above and future items
}
I have existing Model where I am adding Chatto for UI so I am able to create a message with placeholder but unable to figure out the best way to change the same after download.
Library Link
https://github.com/badoo/Chatto
i am using chatto test app with DemoPhotoMessageModel.
then i use the follwing to add
var imgMess = DemoPhotoMessageModel(messageModel: messageModel, imageSize: placeholder.size, image: placeholder)
self.slidingWindow.insertItem(imgMess, position: .bottom)
self.delegate?.chatDataSourceDidUpdate(self)
ImageDownloader.default.downloadImage(with: downloadURL, options: [], progressBlock: nil) {[unowned self]
(image, error, url, data) in
print("Downloaded Image: \(image)")
if let img = image, let imgData = UIImagePNGRepresentation(img){
imgMess.setImage(img: img) //I updated the default implementation changing the image from var to let constant
}
}
Wha I have also tried is updating the object in slidingWindow itself. That also doesn't work. What will be the possible solution to create a new object with new uid or anything else.
You can download image in willBeShown() method of view model. As you need to pass url to view model, you need to subclass couple of classes. Please see the full solution in the gist. Please feel free to ask any questions.
I am developing a chat app using parse. I want to play the vodeo when users click on the video message and Display expandable image when the user click on the picture message. for that I need to differentiate image and video. Kindly guide me to do that...
Surely the easiest way will be of course to look at the file extension...?
For future googlers ... on didTapMessageBubbleAtIndexPath delegate you should check for item class
let message = yourMessageArray[indexPath.item]
if message.isMediaMessage() {
if message.media().isKindOfClass(JSQPhotoMediaItem) {
//Handle image
} else if message.media().isKindOfClass(JSQVideoMediaItem) {
let video = message.media() as! JSQVideoMediaItem
let videoURL = video.fileURL
}
}
Save this information in another field on Parse during the asset upload.
I am developing a phoneGap application in IOS where I use getPhoto('Camera.PictureSourceType.PHOTOLIBRARY');
to access the photo library and select an image. following is the onPhotoURISuccess method where I need to get the url of the image and pass it to my native plugin to validate it's filesize, resolution and file extension.
this is my getPhoto() method
// A button will call this function
function getPhoto(source)
{
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 100,
destinationType: navigator.camera.DestinationType.NATIVE_URI, sourceType: source });
}
and this is the onPhotoURISuccess method,
// Called when a photo is successfully retrieved
function onPhotoURISuccess(imageURI)
{
img_uri = imageURI;
console.log('NATIVE_URI==>'+img_uri);
// Get image handle
var imgPrev = document.getElementById('imgPreview');
// Unhide image elements
imgPrev.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
imgPrev.src = imageURI;
}
I have three options for this according to the phoneGap documentation. using DATA_URL, FILE_URI or NATIVE_URI.
FILE_URI seems to be hiding underlying data of the image where it always returns me a jpeg image thus the actual extension is hidden
assets-library://asset/asset.JPG?id=5CF16D20-9A80-483A-AC1C-9692123610B1&ext=JPG
I want to know how to get the actual image name along with the extension from this.
I need to get the image name and validate the extension.
someone please do help me with posssible approach for me to follow
thanks in advance
If you could get an url to asset, which is
assets-library://asset/asset.JPG?id=5CF16D20-9A80-483A-AC1C-9692123610B1&ext=JPG
You can get real name of file, by this asset:
NSString* originalFileName = [[yourALAsset defaultRepresentation] filename];
Can you use the camera of an iOS device in an AS3 app? If so, how?
Yep it's really easy, there are many ways to access the camera in AS3.
Firstly, the same way as you access the camera in normal AS3 applications:
var camera:Camera = Camera.getCamera();
var video=new Video();
video.attachCamera(camera);
this.addChild(video);
This will display the camera in the current display object.
You can also ask for images from the Camera roll using the CameraRoll class:
import flash.media.CameraRoll;
var cameraRoll:CameraRoll = new CameraRoll();
if(CameraRoll.supportsBrowseForImage)
{
cameraRoll.addEventListener(MediaEvent.SELECT, imageSelected);
cameraRoll.addEventListener(Event.CANCEL, browseCancelled);
cameraRoll.addEventListener(ErrorEvent.ERROR, mediaError);
// Ask the user to select an image
cameraRoll.browseForImage();
}
You can use the native "camera" application to take a photo:
import flash.media.CameraUI;
var cameraUI:CameraUI = new CameraUI();
if (CameraUI.isSupported )
{
cameraUI.addEventListener(MediaEvent.COMPLETE, imageSelected);
cameraUI.addEventListener(Event.CANCEL, browseCancelled);
cameraUI.addEventListener(ErrorEvent.ERROR, mediaError);
cameraUI.launch(MediaType.IMAGE);
}
Hope that points you in the right direction.