mirror of
https://gitee.com/shuto/cordova-plugin-file-opener2.git
synced 2025-01-31 12:02:49 +08:00
- Added iOS support
- Upped the version to 1.0.4
This commit is contained in:
parent
bfb6437405
commit
7235ec4a0d
50
plugin.xml
50
plugin.xml
@ -1,31 +1,39 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?><plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
||||||
id="io.github.pwlin.cordova.plugins.fileopener2"
|
xmlns:android="http://schemas.android.com/apk/res/android" id="io.github.pwlin.cordova.plugins.fileopener2"
|
||||||
version="1.0.3">
|
version="1.0.4">
|
||||||
|
|
||||||
<name>File Opener2</name>
|
<name>File Opener2</name>
|
||||||
<description>A File Opener Plugin for Cordova.</description>
|
<description>A File Opener Plugin for Cordova.</description>
|
||||||
<license>MIT</license>
|
<license>MIT</license>
|
||||||
|
|
||||||
<engines>
|
<engines>
|
||||||
<engine name="cordova" version=">=3.0.0" />
|
<engine name="cordova" version=">=3.0.0" />
|
||||||
</engines>
|
</engines>
|
||||||
|
|
||||||
<js-module src="www/plugins.FileOpener2.js" name="FileOpener2">
|
<js-module src="www/plugins.FileOpener2.js" name="FileOpener2">
|
||||||
<clobbers target="cordova.plugins.fileOpener2" />
|
<clobbers target="cordova.plugins.fileOpener2" />
|
||||||
</js-module>
|
</js-module>
|
||||||
|
|
||||||
<!-- android -->
|
<!-- Android -->
|
||||||
<platform name="android">
|
<platform name="android">
|
||||||
<source-file src="src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener.java" target-dir="src/io/github/pwlin/cordova/plugins/fileopener2" />
|
<source-file src="src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener.java" target-dir="src/io/github/pwlin/cordova/plugins/fileopener2" />
|
||||||
<config-file target="res/xml/config.xml" parent="/*">
|
<config-file target="res/xml/config.xml" parent="/*">
|
||||||
<feature name="FileOpener2">
|
<feature name="FileOpener2">
|
||||||
<param name="android-package" value="io.github.pwlin.cordova.plugins.fileopener2.FileOpener2" />
|
<param name="android-package" value="io.github.pwlin.cordova.plugins.fileopener2.FileOpener2" />
|
||||||
</feature>
|
</feature>
|
||||||
</config-file>
|
</config-file>
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
<platform name="ios">
|
<!-- iOS -->
|
||||||
</platform>
|
<platform name="ios">
|
||||||
|
<config-file target="config.xml" parent="/*">
|
||||||
|
<feature name="FileOpener2">
|
||||||
|
<param name="ios-package" value="FileOpener2" />
|
||||||
|
</feature>
|
||||||
|
</config-file>
|
||||||
|
<source-file src="src/ios/FileOpener2.m" />
|
||||||
|
<header-file src="src/ios/FileOpener2.h" />
|
||||||
|
</platform>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
11
src/ios/FileOpener2.h
Normal file
11
src/ios/FileOpener2.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#import <Cordova/CDV.h>
|
||||||
|
|
||||||
|
@interface FileOpener2 : CDVPlugin <UIDocumentInteractionControllerDelegate> {
|
||||||
|
NSString *localFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@property(nonatomic, strong) UIDocumentInteractionController *controller;
|
||||||
|
|
||||||
|
- (void) open: (CDVInvokedUrlCommand*)command;
|
||||||
|
|
||||||
|
@end
|
59
src/ios/FileOpener2.m
Normal file
59
src/ios/FileOpener2.m
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#import "FileOpener2.h"
|
||||||
|
#import <Cordova/CDV.h>
|
||||||
|
|
||||||
|
#import <QuartzCore/QuartzCore.h>
|
||||||
|
#import <MobileCoreServices/MobileCoreServices.h>
|
||||||
|
|
||||||
|
@implementation FileOpener2
|
||||||
|
@synthesize controller = docController;
|
||||||
|
|
||||||
|
- (void) open: (CDVInvokedUrlCommand*)command {
|
||||||
|
|
||||||
|
NSString *path = [command.arguments objectAtIndex:0];
|
||||||
|
//NSString *uti = [command.arguments objectAtIndex:1];
|
||||||
|
|
||||||
|
CDVViewController* cont = (CDVViewController*)[ super viewController ];
|
||||||
|
|
||||||
|
NSArray *dotParts = [path componentsSeparatedByString:@"."];
|
||||||
|
NSString *fileExt = [dotParts lastObject];
|
||||||
|
|
||||||
|
NSString *uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL);
|
||||||
|
|
||||||
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
|
//NSLog(@"path %@, uti:%@", path, uti);
|
||||||
|
NSURL *fileURL = nil;
|
||||||
|
|
||||||
|
fileURL = [NSURL URLWithString:path];
|
||||||
|
localFile = fileURL.path;
|
||||||
|
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
|
||||||
|
docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
|
||||||
|
docController.delegate = self;
|
||||||
|
docController.UTI = uti;
|
||||||
|
|
||||||
|
CGRect rect = CGRectMake(0, 0, 1000.0f, 150.0f);
|
||||||
|
CDVPluginResult* pluginResult = nil;
|
||||||
|
BOOL wasOpened = [docController presentOptionsMenuFromRect:rect inView:cont.view animated:NO];
|
||||||
|
//presentOptionsMenuFromRect
|
||||||
|
//presentOpenInMenuFromRect
|
||||||
|
|
||||||
|
if(wasOpened) {
|
||||||
|
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @""];
|
||||||
|
//NSLog(@"Success");
|
||||||
|
} else {
|
||||||
|
NSDictionary *jsonObj = [ [NSDictionary alloc]
|
||||||
|
initWithObjectsAndKeys :
|
||||||
|
@"9", @"status",
|
||||||
|
@"Could not handle UTI", @"message",
|
||||||
|
nil
|
||||||
|
];
|
||||||
|
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj];
|
||||||
|
//NSLog(@"Could not handle UTI");
|
||||||
|
}
|
||||||
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
Loading…
Reference in New Issue
Block a user