add file open
This commit is contained in:
8
Assets/3rd/DocumentHandler/Runtime/Plugins/iOS.meta
Normal file
8
Assets/3rd/DocumentHandler/Runtime/Plugins/iOS.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 758b72d97ebaec34195e3f662c0334af
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,87 @@
|
||||
// Credits: https://answers.unity.com/questions/1337996/ios-open-docx-file-from-applicationpersistentdata.html
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
@interface DocumentHandler : NSObject <UIDocumentInteractionControllerDelegate>
|
||||
{
|
||||
NSURL * fileURL;
|
||||
}
|
||||
|
||||
- (id)initWithURL:(NSURL*)unityURL;
|
||||
|
||||
- (void)UpdateURL:(NSURL*)unityURL;
|
||||
|
||||
- (bool)OpenDocument;
|
||||
|
||||
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation DocumentHandler
|
||||
|
||||
- (id)initWithURL:(NSURL*)unityURL
|
||||
{
|
||||
self = [super init];
|
||||
fileURL = unityURL;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)UpdateURL:(NSURL*)unityURL {
|
||||
fileURL = unityURL;
|
||||
}
|
||||
|
||||
- (bool)OpenDocument {
|
||||
|
||||
UIDocumentInteractionController *interactionController =
|
||||
[UIDocumentInteractionController interactionControllerWithURL: fileURL];
|
||||
|
||||
// Configure Document Interaction Controller
|
||||
[interactionController setDelegate:self];
|
||||
|
||||
[interactionController presentPreviewAnimated:YES];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
|
||||
return UnityGetGLViewController();
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
static DocumentHandler* docHandler = nil;
|
||||
|
||||
// Converts C style string to NSString
|
||||
NSString* CreateNSString (const char* string)
|
||||
{
|
||||
if (string)
|
||||
return [NSString stringWithUTF8String: string];
|
||||
else
|
||||
return [NSString stringWithUTF8String: ""];
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
bool _OpenDocument (const char* path)
|
||||
{
|
||||
// Convert path to URL
|
||||
NSString * stringPath = CreateNSString(path);
|
||||
|
||||
NSURL *unityURL = [NSURL fileURLWithPath:stringPath];
|
||||
|
||||
if (docHandler == nil)
|
||||
docHandler = [[DocumentHandler alloc] initWithURL:unityURL];
|
||||
|
||||
else
|
||||
[docHandler UpdateURL:unityURL];
|
||||
|
||||
[docHandler OpenDocument];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93804f9d06962764c8ecf5d676d9c4e9
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
tvOS: tvOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user