Skip to content

Commit

Permalink
[#74k21c] Potential fix to issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh O committed Mar 2, 2020
1 parent 1db4d5e commit c6b2a2d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
18 changes: 13 additions & 5 deletions src/ios/OpenWithPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,14 @@ - (void) pluginInitialize {
// You can listen to more app notifications, see:
// http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006728-CH3-DontLinkElementID_4

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResume) name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(defaultsChanged:) name:NSUserDefaultsDidChangeNotification object:nil];

// NOTE: if you want to use these, make sure you uncomment the corresponding notification handler

// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onPause) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResume) name:UIApplicationWillEnterForegroundNotification object:nil];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onOrientationWillChange) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onOrientationDidChange) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];

// Added in 2.5.0
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pageDidLoad:) name:CDVPageDidLoadNotification object:self.webView];
//Added in 4.3.0
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillAppear:) name:CDVViewWillAppearNotification object:nil];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidAppear:) name:CDVViewDidAppearNotification object:nil];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillDisappear:) name:CDVViewWillDisappearNotification object:nil];
Expand All @@ -154,6 +152,16 @@ - (void) pluginInitialize {
[self info:@"[pluginInitialize] OK"];
}

- (void)defaultsChanged:(NSNotification *)notification {
// Get the user defaults
NSUserDefaults *defaults = (NSUserDefaults *)[notification object];

NSLog(@"%@", [defaults objectForKey:@"dismissedShareExtension"]);
if ([defaults objectForKey:@"dismissedShareExtension"] != nil){
[self checkForFileToShare];
}
}

- (void) onReset {
[self info:@"[onReset]"];
self.userDefaults = [[NSUserDefaults alloc] initWithSuiteName:SHAREEXT_GROUP_IDENTIFIER];
Expand Down
22 changes: 10 additions & 12 deletions src/ios/ShareExtension/ShareViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,17 @@ - (void) finishSelectingPost:(NSItemProvider*)itemProvider data:(NSData*)data ur

// Emit a URL that opens the cordova app
NSString *url = [NSString stringWithFormat:@"%@://image", SHAREEXT_URL_SCHEME];

// Not allowed:
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

// Crashes:
// [self.extensionContext openURL:[NSURL URLWithString:url] completionHandler:nil];

// From https://stackoverflow.com/a/25750229/2343390
// Reported not to work since iOS 8.3
// NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
// [self.webView loadRequest:request];

[self openURL:[NSURL URLWithString:url]];

double delayInSeconds = 1.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
NSTimeInterval today = [[NSDate date] timeIntervalSince1970];
NSString *intervalString = [NSString stringWithFormat:@"%f", today];

[self.userDefaults setObject:intervalString forKey:@"dismissedShareExtension"];
[self.userDefaults synchronize];
});

// Inform the host that we're done, so it un-blocks its UI.
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
Expand Down

0 comments on commit c6b2a2d

Please sign in to comment.