mirror of
https://gitee.com/shuto/cordova-plugin-file-opener2.git
synced 2025-01-31 12:02:49 +08:00
Merge pull request #155 from deltragon/master
iOS: use contentType if provided, otherwise fall back to file extension
This commit is contained in:
commit
021a0ac73d
@ -32,24 +32,25 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
- (void) open: (CDVInvokedUrlCommand*)command {
|
- (void) open: (CDVInvokedUrlCommand*)command {
|
||||||
|
|
||||||
NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||||
NSString *contentType = nil;
|
NSString *contentType = [command.arguments objectAtIndex:1];
|
||||||
BOOL showPreview = YES;
|
BOOL showPreview = YES;
|
||||||
|
|
||||||
if([command.arguments count] == 2) { // Includes contentType
|
if ([command.arguments count] >= 3) {
|
||||||
contentType = [command.arguments objectAtIndex:1];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([command.arguments count] == 3) {
|
|
||||||
showPreview = [[command.arguments objectAtIndex:2] boolValue];
|
showPreview = [[command.arguments objectAtIndex:2] boolValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
CDVViewController* cont = (CDVViewController*)[super viewController];
|
CDVViewController* cont = (CDVViewController*)[super viewController];
|
||||||
self.cdvViewController = cont;
|
self.cdvViewController = cont;
|
||||||
|
NSString *uti = nil;
|
||||||
|
|
||||||
|
if([contentType length] == 0){
|
||||||
NSArray *dotParts = [path componentsSeparatedByString:@"."];
|
NSArray *dotParts = [path componentsSeparatedByString:@"."];
|
||||||
NSString *fileExt = [dotParts lastObject];
|
NSString *fileExt = [dotParts lastObject];
|
||||||
|
|
||||||
NSString *uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL);
|
uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL);
|
||||||
|
} else {
|
||||||
|
uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)contentType, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
NSURL *fileURL = [NSURL URLWithString:path];
|
NSURL *fileURL = [NSURL URLWithString:path];
|
||||||
|
Loading…
Reference in New Issue
Block a user