How to get all PHAssets from MacOS's Photo Library - objective-c

I want to parse all images from my MacOS Photos Library, using PHAsset. However all examples I find are only working for iOS, like the one below, where the last line, which retrieves the assets is not available on macos framework:
NSMutableArray *photos = [[NSMutableArray alloc] init];
PHFetchOptions *allPhotosOptions = [[PHFetchOptions alloc] init];
allPhotosOptions.sortDescriptors = #[[NSSortDescriptor sortDescriptorWithKey:#"creationDate" ascending:YES]];
// Below compilation error as fetchAssetsWithMediaType is only on iOS framework
PHFetchResult *allPhotos = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:allPhotosOptions];
What fetchAssets command should I use on MacOS (version 10.13), or is there another way to do so ?

The Photos framework — or at least, the main subset of that framework, which provides apps with read/write access to the entire Photos library — is not available in macOS.
Photos and PhotosUI are present in macOS, but only in support of specific app-extension features:
Photo Editing extensions. The user invokes these from the Photos app while in Edit mode for a single asset, and it provides direct access to the photo/video data for that asset, so it doesn’t even use the PHAsset class.
Photo Project extensions. These involve collections of assets and selectively loading data for each, so more of the PHAsset/PHImageManager system is present. However, it’s still a reduced subset compared to iOS (only what’s needed for a project extension, like fetching the assets in that project), and it’s accessible only to app extensions, not standalone apps.
If you’d like the full Photos framework on macOS, your best bet is to file a feature request with Apple.

As of macOS 10.15 Catalina, the Photos and PhotosUI frameworks are now available on the Mac, for both Catalyst and AppKit apps. So you should be able to transfer almost all iOS code that uses PhotoKit over to your Mac app now, as long as it has 10.15 as a minimum system requirement.

Related

Include ICC Colour Profile in PDF created with Objective-C iOS?

In my Objective-C iOS app I'm creating PDF files using the code:
UIGraphicsPDFRenderer* renderer = [[UIGraphicsPDFRenderer alloc] initWithBounds:pdfSize];
NSData* outputPdfData = [renderer PDFDataWithActions:^(UIGraphicsPDFRendererContext * _Nonnull context) {
[context beginPage];
// draw operations here
}];
The ultimate aim is to then send this PDF to an AirPrinter.
However, due to the printer hardware we're using it looks like it is going to be necessary to embed in to the PDF an ICC colour profile (possibly CMYK) to ensure accurate colour reproduction.
I've done such operations before in .Net but never in Objective-C and so far all of my web searching has been for nought.
Is it possible to embed ICC colour profiles in to the PDF context in Objective-C using the above approach, or if not is there another way to produce PDFs in Objective-C that does allow ICC profile embedding?
After a lot of searching I've concluded this isn't possible. Documentation is thin on the ground and what does exist usually refers to Mac OSX, not iOS.
ColorSync, as suggested by Moose, appears to be restricted to images and UI elements, and I can see no way of including it in PDF creation. Closing.
Maybe you could try to create a colorSync profile for the printer you use, and let the system correctly prepare you document for this printer, or any another one..
ColorSync is supported since OS9.3 on iOS Devices.

Jailbreak console app save photo

I've created a console app for iOS using iOSOpenDev which is trying to write to the camera roll / saved photos. I've granted permission to access the photo library using entitlements (and checked that the access been granted). But I can't seem to get any form of image to save (using any examples online).
I'm using the following method to save the image:
UIImage *test = [UIImage imageNamed:#"test.png"];
UIImageWriteToSavedPhotosAlbum(test,nil,nil,nil);
(when supplied) it never returns any error messages and doesn't write successfully.
I've also tried:
[library writeImageToSavedPhotosAlbum:.....]
With no better results. I think that this is a problem relating to using UIkit from a console app, rather than my implementation of the save methods?
I'm trying to run on iOS 7 & 8 ideally

Why has Xcode 6.1 killed [NSLocale preferredLanguages] in IOS 8 simulators

Yesterday Xcode updated to v6.1.
Now, [NSLocale preferredLanguages] is returning an empty array in the iPhone, but only for IOS 8 - both in iPhone 5 and 6 emulators. IOS 7 simulators are still working fine.
A physical iPhone 6 device doesn't appear to be affected - it's just the simulators.
The usual attempts - clean project, restart Xcode, reboot Mac - have made no difference. So, what's the best strategy - wait for Xcode 6.1.1, or send a complaint to an Apple list (which one) ?
You can use category with currentLocale method swizzling as described in here. The category allows one to override in general language and region settings in the project for all targets at once.
Also you can use scheme settings for each target in separate way.
If you have many localizations in your app,
you can change Application language and Application region in scheme settings for each target. You can even make a separate target for each localization for faster language tests.
Product -> Scheme -> Edit scheme...
I've flagged this for consideration as a dupe. Global preferences aren't working in the iOS 8.1 simulator. Localization is one such global preference. See:
See iOS8.1 Simulator always uses US keyboard layout despite german hardware keyboard
As for "strategy" ... you could just note that it's a known issue documented in the release notes and wait for a fix, or you can file a radar at http://bugreport.apple.com
First, they're simulators and not emulators. Second, I'm not seeing an empty array returned for [NSLocale preferredLanguages] under Xcode 6.1 (6A1052c) and any iOS 8.1 simulator, but I do always see "en" returned regardless of the language selected in the system settings. I do see correct behavior for any iOS 7 simulator, as you note.
I would file a bug complaint if one hasn't already been filed: more info at Changing language on iOS 8.1 simulator does not work.
Setting Product -> Scheme -> Preferences... didn't helped me, so I made a simple workaround:
NSString *language = [[NSLocale preferredLanguages] count] > 0 ?
[[NSLocale preferredLanguages] objectAtIndex:0] :
#"en";

UIVideoAtPathIsCompatibleWithSavedPhotosAlbum returns false when deploying on the iPhone

One of my app's features is to download a mp4 file and store it to the local phone album.
I have tried several approaches since and the result is always the same, it worked on the simulator but not on the actual iPhone. Xcode is version 5.0.1, iPhone 4.
Below is the code I applied on the last attempt before posted here using ASIHttpRequest library and the result is still the same, it worked on the simulator but not the phone itself.
download:
ASIHTTPRequest* request = [ASIHTTPRequest requestWithURL:url]; // url is the address to the mp4 file
NSString* filePath = [NSString stringWithFormat:#"%#%#", NSTemporaryDirectory(), filename]; //filename is the file I save to, e.g. xxx.mp4
[request setDownloadDestinationPath:filePath];
[request setDelegate:self];
[request setDidFinishSelector:#selector[ASIRequestDone:)];
[request setDidFailSelector:#select[ASIRequestFail:)];
when download is finished, save it to the photo album (in ASIRequestDone delegate)
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(filePath))
{
//comes to here when running in simulators
UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, #selector(video:didFinishSavingWithError:cotextInfo:),nil);
}
else
{
//always comes to here when running on the actual iPhone.
}
I have checked the pathFile it's this
/private/var/mobile/Applications/xxxxxxxxxx/tmp/xxxxx.mp4
which is alright to me. What I am not getting is it works fine when running on Simulator and hence I am stuck not sure what to do next. (I have also checked the permission accessing the the photo albums and yes the app has it).
I also tried to removed the compatible checking and went straight into the method UISaveVideoAtPathToSavedPhotosAlbum, it didn't throw any error on delegate didFinishSavingWithError. however, the video didn't show up on the photo album either, I am guessing it's correct as the phone seems to say that video is not compatible to be shown on the album. Again, my issue is that it does work on the simulator and how do I fix this on the actual iphone, e.g. why it thinks the video is not compatible? is something to do with the mp4 itself or is it something to do during the download step? What could I do next to resolve the issue? (ps. I also have control over the mp4 files, is there a list of mp4 compatibility on the iphone that you know? I am thinking perhaps it's genuine that the file is not compatible on the phone (but on the simulator!?))
Found the answer to my question and I hope it could help out someone who suffers from the same issue. Turns out video resolution is the factor between the simulator and the actual phone when it comes to store video to the gallery; to be specific:
Compatibility checking UIVideoAtPathIsCompatibleWithSavedPhotosAlbum would FAIL on the actual phone but would PASS on the simulator given a sample clip capturrd as 1080p. I came cross this link a week after my post with luck.
"What video formats are compatible with the assets library?"
And I did the experiment similar to that by capturing 720p video clips instead and all files were able to be saved to the gallery. Weird thing is that the actual iphone can play the HLS stream at 1080p; howeve it won't store clips unless they are 720p, not to me anyway. And the misleading bit is that the simulator can actually do 1080p.

Download and display PDF with Trigger.io and jQuery Mobile

We are going to develop a mobile app (iOS and Android), which should provide downloading and storing several user-selected PDF files and viewing them within the app (iOS with WebView) or with an external PDF Viewer (Android).
My Question is: Is this possible with Trigger.io? I didn't find anything concerning this in the official documentation. Can we do something with the file or the child browser / tabs module? If yes, do you have any examples?
Note: We will use Backbone.js and jQuery Mobile as additional libraries.
The Android webview doesn't allow for inline opening of PDFs - you can test that by opening e.g. http://trigger.io/cross-platform-application-development-blog/wp-content/uploads/2012/05/trigger.io-whitepaper.pdf in your stock browser.
On iOS, you can use:
forge.tools.getURL('my_file.pdf',
function (file) {
forge.tabs.open(file);
}
);
But that won't work on Android (tested on 2.3, 3 and 4.0).
Short answer - yes.
Downloading, storing, then showing/referencing later can definitely be done. Check out the forge.file documentation.
I have not tried the child browser feature yet. Although the tabs module will work, I think its best to just let the device (and its user settings) decide how to display/render the PDF. I am only saying this because my devices (especially the Android ones... 2.3 and 4.x) tend to behave differently. Either way... the device's "back button" always gets me back to where I left off in my trigger.io app.