EddyVerbruggen / SocialSharing-PhoneGap-Plugin

👨‍❤️‍💋‍👨 Cordova plugin to share text, a file (image/PDF/..), or a URL (or all three) via the native sharing widget
MIT License
1.78k stars 909 forks source link

Dialog show twice #465

Closed kfmaurice closed 8 years ago

kfmaurice commented 8 years ago

Hi there,

firsto of all, thanks for the plugin. I'm having a weird issue with the plugin during development. On the IPhone 4s, the dialog shows up twice: first once and then after 1s again. Here is the only call I used:

window.plugins.socialsharing.share(message, title, 'www/img/icon.png', url);

Is there something I should do to prevent it ? It is really annoying since the dialog is still visible after the user taps the cancel button once. To get rid of it, the user has in fact to tap twice to dismiss the two dialogs.

Thanks in advance,

Maurice

jmail commented 8 years ago

Can you please give us iOS version to be able to produce same environment?

kfmaurice commented 8 years ago

It is developed with

and deployed for testing on IPhone 4s with iOS 9.1 installed.

jmail commented 8 years ago

I've just made same test leaving Ionic aside. It works OK. Can you please try using it with clean cordova? Just to exclude Ionic as potential issue?

jmail commented 8 years ago

Checked on two 4ses 5 5c 5s and 6s plus with clean project and simple on button click.

It looks like specific issue with your app. Please try using completly new clean project without anything else and try adding features you require inside your app untill you found out what is going on.

kfmaurice commented 8 years ago

Hi jmail,

thanks anyway. I couldn't figure out, why the dialog pops up twice. The code in the event handler runs in fact only twice when your plugin is used. But this doesn't happen, with another code. I guess there must be some dependencies between other parts of the application which triggers the second run.

Anyway, I circumvented the issue by using a timer which resets a watcher to prevent the code to be called twice. It's not a real fix but it works. I hope some update in ionic in the future would make this fix obsolete.

Cheers,

Maurice

scottopolis commented 8 years ago

I'm having this issue with Ionic as well. If I add logs, it only calls the function once, but the native share dialog shows twice.

I am using iOS9.2 and Xcode 7.2, SocialSharing 5.0.7.

scottopolis commented 8 years ago

FYI - I fixed this issue by rolling back to version 5.0.5.

EddyVerbruggen commented 8 years ago

@scottopolis Interesting issue.. I've checked all changes between 5.0.5 and 5.0.7 and they are 90% Android. Nothing relevant for iOS really.

I can't reproduce it on my 9.1 device, so I'll upgrade to 9.2 and test again.

EddyVerbruggen commented 8 years ago

Tested the latest version with iOS 9.2. No issues as well. @scottopolis can you share a project which reproduces this error? Otherwise my hands are tied..

scottopolis commented 8 years ago

Thanks @EddyVerbruggen, I'll investigate further and if I can't figure it out I'll post a project.

ituhin commented 8 years ago

for me also it comes twice on my iphone 4s on ios 8.4.1

Cordova CLI: 5.4.1 Gulp version: CLI version 3.9.0 Gulp local: Local version 3.9.0 Ionic Version: 1.2.1 Ionic CLI Version: 1.7.12 Ionic App Lib Version: 0.6.5 ios-deploy version: 1.7.0 ios-sim version: 4.1.1 OS: Mac OS X El Capitan Node Version: v0.12.7 Xcode version: Xcode 7.2 Build version 7C62b

mintzhao commented 8 years ago

I have the same bug. It happens random, don't know why

santimacia commented 8 years ago

Same problem here with ios 9.2 and ionic, what can we do

Cordova CLI: 5.3.3 Gulp version: CLI version 3.9.0 Gulp local: Local version 3.9.0 Ionic Version: 1.1.1 Ionic CLI Version: 1.7.11 Ionic App Lib Version: 0.6.5 ios-deploy version: 1.7.0 ios-sim version: 3.1.1 OS: Mac OS X El Capitan Node Version: v4.1.0 Xcode version: Xcode 7.2 Build version 7C68

EddyVerbruggen commented 8 years ago

Can somebody post a project (as small as possible) reproducing this on github so we can all take a look? Thanks.

ituhin commented 8 years ago

well theres nothing much to show actually. it just happens in ionic env i guess i am blocking it this way... using a flag and a timer

.controller('SettingsCtrl', function ($scope, $cordovaSocialSharing, $timeout){

var flag = 0; // native share window appearing twice
$scope.share = function() {
    if(flag) return;
    if(!flag) flag = 1;
    $cordovaSocialSharing
.share('test message', 'test subject', false, 'http://google.com') // Share via native share sheet
.then(function(result) {
    console.log(result);
  // Success!
    }, function(err) {
  // An error occured. Show a message to the user
        console.log(err);
    });
    $timeout(function() {flag = 0; console.log('wtf');}, 3000);
}

})

EddyVerbruggen commented 8 years ago

I'll take a look if anyone can reproduce this on a plain old Cordova starter app.

ituhin commented 8 years ago

i think in cordova it works fine, its the problem with ionic probably

samwx commented 8 years ago

Same problem here. I switched to version 5.0.5 and everything is ok! Thanks @scottopolis

GC-Mark commented 8 years ago

Also having same issue. iPhone 6, Xcode 7.2 and Ionic.

Seems to happen randomly, but more often on first share after App boot

EddyVerbruggen commented 8 years ago

Still waiting for that testproject. I just tried again with a vanilla Cordova CLI project and just can't reproduce it.

GC-Mark commented 8 years ago

@EddyVerbruggen Here you go. Plain Ionic app with social share button.

Be aware though, I built the app through Xcode 20-30 times and only managed to get the double dialog once. I am not sure yet how to replicate it more regularly

https://github.com/GC-Mark/testapp

EddyVerbruggen commented 8 years ago

@GC-Mark Thanks! I press the sharebutton in the top right. That opens the share sheet. Is that the dialog that opens twice sometimes, or is it fi. the Twitter app popup you choose afterwards?

GC-Mark commented 8 years ago

@EddyVerbruggen Yes, the share sheet that first opens is the one that opens twice.

Over the weekend, I managed to reproduce it 100% of the time. Its a bit of a pain though.

Here's what you need to do...

Open the App > press the share button.

If the share sheet doesn't open twice. Close the share sheet. Then close the app (leave it in the background)

Now, use your phone as normal, then wait long enough (don't know how long this is,I usually waited a couple of hours with lots of other App opens in between) so that the app is 'garbage collected' i.e. when you open the App again, it doesn't resume, it boots with the splash screen. Then press the share button. You will get the share sheet twice. This happens 100% of the time with this method.

Just another small piece of information. You can tell when you are going to get 2 share sheets because when you press the share button, there is a 1-2 second pause before the first share sheet opens, when usually it is pretty instant.

Hope that helps.

GC-Mark commented 8 years ago

@EddyVerbruggen I have found a quicker way to reproduce the issue. Just hard reboot your iPhone (hold power and home button until restart), then open the app and you will get 2 share sheets.

Here's a video of the issue....

share

EddyVerbruggen commented 8 years ago

There's no denying that it happens on your device, but with none of those reproduction paths can I achieve the same result. I'm using the latest plugin from github on an iPhone 6s.

Could it be a specific app in the sharesheet that's triggering an iOS bug perhaps?

GC-Mark commented 8 years ago

I disabled all sharing options and i can still replicate...

img_1275

GC-Mark commented 8 years ago

Just done some more testing.

With all sharing options disabled, I did 10 reboots...I got a duplicate share sheet 3 times, and 7 times it was fine i.e. it was broken 30% of the time.

I then did the same with my normal sharing options selected...I got a duplicate share sheet 9 times, and only 1 time it was fine i.e it was broken 90% of the time.

Anything else i can do to help debug this? Willing to try any suggestions....

EddyVerbruggen commented 8 years ago

Are you able to test this on a different iOS device?

GC-Mark commented 8 years ago

I can, maybe today, but might be sometime next week...

GC-Mark commented 8 years ago

Just tested this in the Simulator for the first time....replicated the issue at the first attempt :confused:

EddyVerbruggen commented 8 years ago

Can you unzip this project, open it in Xcode and run it on your iPhone 6s 9.3 simulator? I just did without seeing this issue.

GC-Mark commented 8 years ago

Just ran that project through Xcode in the iPhone 6s simulator and got the issue the first time of trying....

GC-Mark commented 8 years ago

...actually, my simulator is running iOS 9.2.

Is that an issue?

EddyVerbruggen commented 8 years ago

Woah I just saw it for the first time myself while debugging this issue. I'll look at it some more later today.

EddyVerbruggen commented 8 years ago

Turns out that without Ionic this does not occur. Removing <script src="lib/ionic/js/ionic.bundle.js"></script> from index.html fixes the issue. Try with and without it and simply add an onclick="window.plugins...share(..)" handler to a button on the page. With the bundle the dialog is triggered twice.

You are not alone

Workaround: wrap your call to share() in a timeout:

        setTimeout(function() {
            $cordovaSocialSharing
              .share('Subject', 'Message', null, 'http://www.google.com') // Share via native share sheet
              .then(function(result) {
                  console.log(result);
                  }, function(err) {
                  alert('Sharing failed. Please try again.');
                  });
        }, 500);
AbdallahBaddour commented 8 years ago

I use on-touch="share()" instead of ng-click="share()" to solve this problem.

GC-Mark commented 8 years ago

@EddyVerbruggen Thanks for looking into this. Glad you finally replicated and figured out the cause. Unfortunately, I can still replicate the issue even when using your workaround. Surely even with a timeout, the timeout will just get triggered twice. Don't we need a flag to say the first timeout has been triggered, so don't trigger again as per this comment https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin/issues/465#issuecomment-169343013

@AbdallahBaddour just tried on-touch="share()" and I still get the issue

camkLcbr commented 8 years ago

@AbdallahBaddour on-touch="share()" solved the problem for me (and a rollback to 5.0.5), Thx !

AlmogCohen commented 8 years ago

I followed on what described here on the ionic forum and used on-tap. I recommend updating this plugin documentation before closing this issue since many will probably keep encountering it

jwuliger commented 8 years ago

on-touch="share()" worked for me too! Great find. Thanks!!

EddyVerbruggen commented 8 years ago

@AlmogCohen / @jwuliger Feel free to send a PR to add something to the readme, even if it's not really a problem with this plugin.

GC-Mark commented 8 years ago

on-touch="share()" definitely still had the problem in my testing 😕

VinceOPS commented 8 years ago

Using on-tap did the trick for me (using ionic v1), thanks!

kfmaurice commented 8 years ago

on-touch worked for me too, thx :-)