it's 3 am and ios file imports are finally fixed
This commit is contained in:
@@ -58,129 +58,31 @@ public class IOSLauncher extends IOSApplication.Delegate{
|
|||||||
public void didPickDocumentsAtURLs(UIDocumentBrowserViewController controller, NSArray<NSURL> documentURLs){
|
public void didPickDocumentsAtURLs(UIDocumentBrowserViewController controller, NSArray<NSURL> documentURLs){
|
||||||
if(documentURLs.size() < 1) return;
|
if(documentURLs.size() < 1) return;
|
||||||
|
|
||||||
cont.dismissViewController(true, () -> {});
|
NSURL url = documentURLs.first();
|
||||||
NSFileCoordinator coord = new NSFileCoordinator(null);
|
NSFileCoordinator coord = new NSFileCoordinator(null);
|
||||||
|
url.startAccessingSecurityScopedResource();
|
||||||
try{
|
try{
|
||||||
coord.coordinateReadingItem(documentURLs.get(0), NSFileCoordinatorReadingOptions.None, url -> {
|
coord.coordinateReadingItem(url, NSFileCoordinatorReadingOptions.ForUploading, result -> {
|
||||||
if(url.startAccessingSecurityScopedResource()){
|
|
||||||
|
FileHandle src = Core.files.absolute(result.getAbsoluteURL().getPath());
|
||||||
|
FileHandle dst = Core.files.absolute(getDocumentsDirectory()).child(src.name());
|
||||||
|
src.copyTo(dst);
|
||||||
|
|
||||||
|
Core.app.post(() -> {
|
||||||
try{
|
try{
|
||||||
controller.importDocument(url, new NSURL(getDocumentsDirectory() + "/document"), UIDocumentBrowserImportMode.Copy, (result, error) -> {
|
cons.get(dst);
|
||||||
if(error != null){
|
|
||||||
ui.showErrorMessage("Import error.\n" + error.getLocalizedFailureReason() + "\n" + error.getLocalizedDescription());
|
|
||||||
}else{
|
|
||||||
try{
|
|
||||||
cons.get(Core.files.absolute(url.getPath()));
|
|
||||||
}catch(Throwable t){
|
|
||||||
ui.showException(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}catch(Throwable t){
|
}catch(Throwable t){
|
||||||
ui.showException(t);
|
ui.showException(t);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
/*
|
|
||||||
|
|
||||||
try{
|
|
||||||
int[] tread = {0};
|
|
||||||
|
|
||||||
cons.get(new FileHandle(url.getPath()){
|
|
||||||
@Override
|
|
||||||
public InputStream read(){
|
|
||||||
NSInputStream stream = new NSInputStream(url);
|
|
||||||
|
|
||||||
return new InputStream(){
|
|
||||||
byte[] tmp = {0};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read() throws IOException{
|
|
||||||
read(tmp);
|
|
||||||
return tmp[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read(byte[] bytes, int offset, int length){
|
|
||||||
int read = (int)stream.read(bytes, offset, length);
|
|
||||||
tread[0] += read;
|
|
||||||
return read;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Core.app.post(() -> Core.app.post(() -> Core.app.post(() -> ui.showInfo("Read " + tread[0]))));
|
|
||||||
//cons.get(new FileHandle(url.getAbsoluteString()));
|
|
||||||
}catch(Throwable t){
|
|
||||||
ui.showException(t);
|
|
||||||
|
|
||||||
try{
|
|
||||||
cons.get(new FileHandle(url.getPath()));
|
|
||||||
}catch(Throwable t2){
|
|
||||||
ui.showException(t2);
|
|
||||||
|
|
||||||
try{
|
|
||||||
cons.get(new FileHandle(url.getAbsoluteURL().getPath()));
|
|
||||||
}catch(Throwable t3){
|
|
||||||
ui.showException(t3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}else{
|
|
||||||
ui.showErrorMessage("Failed to access file.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
try{
|
|
||||||
int[] tread = {0};
|
|
||||||
|
|
||||||
cons.get(new FileHandle(url.getPath()){
|
|
||||||
@Override
|
|
||||||
public InputStream read(){
|
|
||||||
NSInputStream stream = new NSInputStream(url);
|
|
||||||
|
|
||||||
return new InputStream(){
|
|
||||||
byte[] tmp = {0};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read() throws IOException{
|
|
||||||
read(tmp);
|
|
||||||
return tmp[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read(byte[] bytes, int offset, int length){
|
|
||||||
int read = (int)stream.read(bytes, offset, length);
|
|
||||||
tread[0] += read;
|
|
||||||
return read;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Core.app.post(() -> Core.app.post(() -> Core.app.post(() -> ui.showInfo("Read " + tread[0]))));
|
|
||||||
}catch(Throwable t){
|
|
||||||
ui.showException(t);
|
|
||||||
}*/
|
|
||||||
});
|
});
|
||||||
}catch(Throwable t){
|
}catch(Throwable e){
|
||||||
ui.showException(t);
|
ui.showException(e);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
|
||||||
try{
|
url.stopAccessingSecurityScopedResource();
|
||||||
controller.importDocument(documentURLs.get(0), new NSURL(getDocumentsDirectory() + "/document"), UIDocumentBrowserImportMode.Copy, (url, error) -> {
|
|
||||||
if(error != null){
|
cont.dismissViewController(true, () -> {});
|
||||||
ui.showErrorMessage("Import error.\n" + error.getLocalizedFailureReason() + "\n" + error.getLocalizedDescription());
|
|
||||||
}else{
|
|
||||||
try{
|
|
||||||
cons.get(Core.files.absolute(url.getPath()));
|
|
||||||
}catch(Throwable t){
|
|
||||||
ui.showException(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}catch(Throwable t){
|
|
||||||
ui.showException(t);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -190,7 +92,6 @@ public class IOSLauncher extends IOSApplication.Delegate{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void didImportDocument(UIDocumentBrowserViewController controller, NSURL sourceURL, NSURL destinationURL){
|
public void didImportDocument(UIDocumentBrowserViewController controller, NSURL sourceURL, NSURL destinationURL){
|
||||||
//cons.get(Core.files.absolute(destinationURL.getAbsoluteString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user