Add NativeImagePicker class for use from the player IOS FileChooser class (#428)

Co-authored-by: richard <richard@dotmodus>
This commit is contained in:
Richard Larkin 2020-03-10 21:24:31 +02:00 committed by GitHub
parent 558f987d9d
commit a583d5db07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 3 deletions

View file

@ -6,7 +6,7 @@ class IosRecipe(CythonRecipe):
url = "src"
library = "libios.a"
depends = ["python"]
pbx_frameworks = ["MessageUI", "CoreMotion", "UIKit", "WebKit"]
pbx_frameworks = ["MessageUI", "CoreMotion", "UIKit", "WebKit", "Photos"]
def install(self):
self.install_python_package(

View 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

View file

@ -2,10 +2,11 @@ from distutils.core import setup, Extension
import os
setup(name='ios',
version='1.0',
version='1.1',
ext_modules=[
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=[ ],
library_dirs=[],
)