Add NativeImagePicker class for use from the player IOS FileChooser class (#428)
Co-authored-by: richard <richard@dotmodus>
This commit is contained in:
parent
558f987d9d
commit
a583d5db07
3 changed files with 49 additions and 3 deletions
recipes/ios
|
@ -6,7 +6,7 @@ class IosRecipe(CythonRecipe):
|
||||||
url = "src"
|
url = "src"
|
||||||
library = "libios.a"
|
library = "libios.a"
|
||||||
depends = ["python"]
|
depends = ["python"]
|
||||||
pbx_frameworks = ["MessageUI", "CoreMotion", "UIKit", "WebKit"]
|
pbx_frameworks = ["MessageUI", "CoreMotion", "UIKit", "WebKit", "Photos"]
|
||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
self.install_python_package(
|
self.install_python_package(
|
||||||
|
|
45
recipes/ios/src/ios_filechooser.m
Normal file
45
recipes/ios/src/ios_filechooser.m
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#include "ios_wrapper.h"
|
||||||
|
|
||||||
|
@interface NativeImagePicker : NSObject
|
||||||
|
@end
|
||||||
|
@implementation NativeImagePicker
|
||||||
|
|
||||||
|
- (NSString*) getFileName:(NSURL *) ns_url {
|
||||||
|
// Return the file name without the path or file extention
|
||||||
|
NSString *image_name = ns_url.pathComponents.lastObject;
|
||||||
|
NSArray *listItems = [image_name componentsSeparatedByString:@"."];
|
||||||
|
NSString *ret = listItems[0];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString*) writeToPNG: (NSDictionary *) info {
|
||||||
|
/* Given the info frozen dictionary returned by the file picker, convert
|
||||||
|
the image selected to a PNG and return the full path. */
|
||||||
|
|
||||||
|
// Get the image name, stripped of path and extention
|
||||||
|
NSString *image_name = [self getFileName: info[UIImagePickerControllerImageURL]];
|
||||||
|
|
||||||
|
// Get the png representation of the image
|
||||||
|
UIImage *image = info[UIImagePickerControllerOriginalImage];
|
||||||
|
NSData *imageData = UIImagePNGRepresentation(image);
|
||||||
|
|
||||||
|
// Generate the final image destination
|
||||||
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||||
|
NSString *documentsDirectory = [paths objectAtIndex:0];
|
||||||
|
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", image_name]];
|
||||||
|
|
||||||
|
// Write the image data to the file
|
||||||
|
if (![imageData writeToFile:imagePath atomically:NO])
|
||||||
|
{
|
||||||
|
NSLog(@"Failed to cache image data to disk");
|
||||||
|
return @"";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSLog(@"the cachedImagedPath is %@",imagePath);
|
||||||
|
return imagePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@end
|
|
@ -2,10 +2,11 @@ from distutils.core import setup, Extension
|
||||||
import os
|
import os
|
||||||
|
|
||||||
setup(name='ios',
|
setup(name='ios',
|
||||||
version='1.0',
|
version='1.1',
|
||||||
ext_modules=[
|
ext_modules=[
|
||||||
Extension(
|
Extension(
|
||||||
'ios', ['ios.c', 'ios_utils.m', 'ios_mail.m', 'ios_browser.m'],
|
'ios', ['ios.c', 'ios_utils.m', 'ios_mail.m', 'ios_browser.m',
|
||||||
|
'ios_filechooser.m'],
|
||||||
libraries=[ ],
|
libraries=[ ],
|
||||||
library_dirs=[],
|
library_dirs=[],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue