From 63cfc0604a9ee78f03b5ab0bdb3eacdd23904409 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 26 Mar 2019 16:13:23 +0100 Subject: [PATCH] MOBILE-2915 ios: Fix shared files treated twice in iOS 12 --- src/core/sharedfiles/sharedfiles.module.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/sharedfiles/sharedfiles.module.ts b/src/core/sharedfiles/sharedfiles.module.ts index 82c41169a..692ace04d 100644 --- a/src/core/sharedfiles/sharedfiles.module.ts +++ b/src/core/sharedfiles/sharedfiles.module.ts @@ -44,15 +44,27 @@ export class CoreSharedFilesModule { delegate.registerHandler(handler); if (platform.is('ios')) { + let lastCheck = 0; + // Check if there are new files at app start and when the app is resumed. helper.searchIOSNewSharedFiles(); platform.resume.subscribe(() => { - helper.searchIOSNewSharedFiles(); + // Wait a bit to make sure that APP_LAUNCHED_URL is treated before this callback. + setTimeout(() => { + if (Date.now() - lastCheck < 1000) { + // Last check less than 1s ago, don't do anything. + return; + } + + lastCheck = Date.now(); + helper.searchIOSNewSharedFiles(); + }, 200); }); eventsProvider.on(CoreEventsProvider.APP_LAUNCHED_URL, (url) => { if (url && url.indexOf('file://') === 0) { // We received a file in iOS, it's probably a shared file. Treat it. + lastCheck = Date.now(); helper.searchIOSNewSharedFiles(url); } });