Last active
March 24, 2017 12:43
-
-
Save kosso/614ff574b14389b2426c6c6b5792487f to your computer and use it in GitHub Desktop.
Titanium iOS SDK hack to allow picking animated GIFs from Camera Roll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add before the sendPickerSuccess in MediaModule.m | |
// ~ line 2104 | |
// Provides event.gifmedia with the success event if a GIF is picked as a TiBlob. | |
// If so, the event.media is the first frame as a PNG. | |
// Kosso | |
// See if it's a GIF. Use the referenceURL | |
NSURL *referenceURL = [editingInfo objectForKey:UIImagePickerControllerReferenceURL]; | |
NSString *_mime = [Mimetypes mimeTypeForExtension:[referenceURL path]]; | |
if ([_mime isEqualToString:@"image/gif"]) { | |
PHAsset * asset = [[PHAsset fetchAssetsWithALAssetURLs:@[referenceURL] options:nil] lastObject]; | |
if (asset) { | |
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; | |
options.synchronous = YES; | |
options.networkAccessAllowed = NO; | |
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; | |
[[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { | |
NSNumber * isError = [info objectForKey:PHImageErrorKey]; | |
NSNumber * isCloud = [info objectForKey:PHImageResultIsInCloudKey]; | |
if ([isError boolValue] || [isCloud boolValue] || ! imageData) { | |
// fail | |
} else { | |
// success, data is in imageData | |
// NSLog(@"[INFO] GOT THE GIF!! %d", imageData.length); | |
TiBlob *gifblob = [[[TiBlob alloc] initWithData:imageData mimetype:@"image/gif"] autorelease]; | |
[dictionary setObject:gifblob forKey:@"gifmedia"]; | |
imageData = nil; | |
} | |
}]; | |
} | |
} | |
_mime = nil; | |
// end GIF | |
[self sendPickerSuccess:dictionary]; | |
...... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment