summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@theqtcompany.com>2015-04-16 13:14:19 +0200
committerRichard Moe Gustavsen <richard.gustavsen@theqtcompany.com>2015-05-06 19:46:45 +0000
commitc4054ab1b7761c7a8c3ba9d5c6527eeae61da5b6 (patch)
tree956a4b2e4446fa604924305ff53ea99b2587a4e8 /src/plugins/platforms/ios/qiosfileengineassetslibrary.mm
parent1665e0d105fd97bfa2c6cd459ba20aa87d8b2a81 (diff)
ios: add fallback in QIOSFileEngineAssetsLibrary for loading assets from ALAssetsGroupPhotoStream
[ALAssetsLibrary assetForUrl:] will not load assets coming from ALAssetsGroupPhotoStream. Such assets can be stored in the cloud and might need to be downloaded first. Unfortunately, forcing that to happen is hidden behind private APIs ([ALAsset requestDefaultRepresentation]). So if the user through QIOSFileDialog opens the photo stream folder and chooses a photo inside it, QIOSFileEngineAssetsLibrary will fail loading it. This patch implements a work-around that basically asks ALAssetLibrary to enumerate all assets in the photo library, and stop once we find an asset with the correct url. At that point we also have a pointer to a ALAsset that can be used for loading. This is off course a slow way of loading an asset, but at least better than not being able to load it at all. Change-Id: Ie50344974f043f909ee94fa12e7eb4a40a666c7f Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Diffstat (limited to 'src/plugins/platforms/ios/qiosfileengineassetslibrary.mm')
-rw-r--r--src/plugins/platforms/ios/qiosfileengineassetslibrary.mm20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm b/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm
index 5e73e615e2..84a0b57e61 100644
--- a/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm
+++ b/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm
@@ -206,6 +206,26 @@ public:
NSURL *url = [NSURL URLWithString:assetUrl.toNSString()];
m_assetLibrary = [[ALAssetsLibrary alloc] init];
[m_assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) {
+
+ if (!asset) {
+ // When an asset couldn't be loaded, chances are that it belongs to ALAssetsGroupPhotoStream.
+ // Such assets can be stored in the cloud and might need to be downloaded first. Unfortunately,
+ // forcing that to happen is hidden behind private APIs ([ALAsset requestDefaultRepresentation]).
+ // As a work-around, we search for it instead, since that will give us a pointer to the asset.
+ QIOSAssetEnumerator e(m_assetLibrary, ALAssetsGroupPhotoStream);
+ while (e.hasNext()) {
+ ALAsset *a = e.next();
+ QString url = QUrl::fromNSURL([a valueForProperty:ALAssetPropertyAssetURL]).toString();
+ if (url == assetUrl) {
+ asset = a;
+ break;
+ }
+ }
+ }
+
+ if (!asset)
+ engine->setError(QFile::OpenError, QLatin1String("could not open image"));
+
m_asset = [asset retain];
dispatch_semaphore_signal(semaphore);
} failureBlock:^(NSError *error) {