InstagramPlugin icon indicating copy to clipboard operation
InstagramPlugin copied to clipboard

Warning: Attempt to present on whose view is not in the window hierarchy

Open ne0c0de opened this issue 8 years ago • 6 comments

Hi

I'm trying to use Instagram plugin on IAB (i mean i'm trying to use it on a window that i opened with window.open)

When i try to share on Android it's working without any problem.

But when i try to make a share on iOS (on latest version) i got this error:

    Warning: Attempt to present <_UIDocumentActivityViewController: 0x13700c600> on <MainViewController: 0x136540fd0> whose view is not in the window hierarchy!

and nothing opened (share menu didn't open)

When i debug it, i saw that it's getting the error on this line:

    [self.interactionController presentOpenInMenuFromRect:CGRectZero inView:self.webView animated:YES];

What should i need to do for make it work?

Thanks

ne0c0de avatar Feb 08 '16 15:02 ne0c0de

any chance that you reproduce it?

ne0c0de avatar Feb 11 '16 10:02 ne0c0de

Can you replicate the issue using the sample application using your environment?

vstirbu avatar Feb 11 '16 11:02 vstirbu

Sure, i will prepare it and give a link of it

ne0c0de avatar Feb 11 '16 13:02 ne0c0de

Here's the sample cordova application that i created:

https://www.dropbox.com/s/g4c72huf8bvecyw/sample.zip?dl=0

It's including Cordova InAppBrowser plugin which is accessible from https://github.com/apache/cordova-plugin-inappbrowser and your Instagram Plugin.

You should run this on a real iphone device that have instagram application installed to reproduce the issue. Open the application and then click Open InAppBrowser button. It will open http://ajan.im/test.html url in an inappbrowser. When you click "Share on Instagram" link on that page, the error occurres.

Here's the latest debug lines when i tried it:

2016-02-11 16:52:59.607 HelloCordova[543:661599] Apache Cordova native platform version 3.6.3 is starting. 2016-02-11 16:52:59.609 HelloCordova[543:661599] Multi-tasking -> Device: YES, App: YES 2016-02-11 16:52:59.621 HelloCordova[543:661599] Unlimited access to network resources 2016-02-11 16:52:59.632 HelloCordova[543:661599]

Started backup to iCloud! Please be careful. Your application might be rejected by Apple if you store too much data. For more information please read "iOS Data Storage Guidelines" at: https://developer.apple.com/icloud/documentation/data-storage/

2016-02-11 16:53:00.452 HelloCordova[543:661599] Resetting plugins due to page load. 2016-02-11 16:53:00.874 HelloCordova[543:661599] Finished load of: file:///var/mobile/Containers/Bundle/Application/C40F7281-253C-4329-A537-232E08EAAE91/HelloCordova.app/www/index.html 2016-02-11 16:53:29.921 HelloCordova[543:661599] Setting the WebView's frame to {{0, 0}, {320, 524}} 2016-02-11 16:53:29.921 HelloCordova[543:661599] Setting the WebView's frame to {{0, 0}, {320, 568}} 2016-02-11 16:53:29.936 HelloCordova[543:661599] THREAD WARNING: ['InAppBrowser'] took '87.792236' ms. Plugin should use a background thread. 2016-02-11 16:54:42.621 HelloCordova[543:661599] webView:didFailLoadWithError - -999: The operation couldn’t be completed. (NSURLErrorDomain error -999.) 2016-02-11 16:54:42.623 HelloCordova[543:661599] THREAD WARNING: ['InAppBrowser'] took '11.537109' ms. Plugin should use a background thread. 2016-02-11 16:54:44.631 HelloCordova[543:661599] open in instagram 2016-02-11 16:54:44.675 HelloCordova[543:661599] Warning: Attempt to present <_UIDocumentActivityViewController: 0x15d8e3000> on <MainViewController: 0x15d688950> whose view is not in the window hierarchy! 2016-02-11 16:54:44.676 HelloCordova[543:661599] THREAD WARNING: ['Instagram'] took '50.194092' ms. Plugin should use a background thread.

ne0c0de avatar Feb 11 '16 14:02 ne0c0de

i just find a workaround for the problem:

             `

ref.close(); setTimeout(function(){ console.log("before instagram lastUrl: " + lastUrl); Instagram.share('insta', "", function (err) { if (err != null && (err == "iini" || err.indexOf("No Activity found to handle Intent") != -1)){ console.log("instagram is not installed"); alert("Instagram not installed"); } else { console.log("err on instagram share:"); console.log(err); } ref = cordova.InAppBrowser.open(lastUrl, '_blank', 'location=no,hardwareback=yes,toolbar=no'); //console.log("lastUrl: " + lastUrl); }); },1000); `

This will close the inappbrowser and open the share menu. After click on instagram button i'm opening the inappbrowser again.

But the new problem is, if i press the cancel button in share menu it will not trigger the callback function. And this cause the inappbrowser stay closed.

in this code:

`

  • (void) documentInteractionControllerDidDismissOpenInMenu: (UIDocumentInteractionController *) controller { CDVPluginResult *result;

    if (self.toInstagram) { result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [self.commandDelegate sendPluginResult:result callbackId: self.callbackId]; } else { result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:2]; [self.commandDelegate sendPluginResult:result callbackId: self.callbackId]; } } `

this didn't trigger the callback function. How can i achieve this?

ne0c0de avatar Feb 11 '16 17:02 ne0c0de

any chance that you could test it?

ne0c0de avatar Feb 15 '16 06:02 ne0c0de