Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seems that JsBridge not working with Xamarin.iOS Version: 6.2.7.1 #3

Closed
volaticus opened this issue Jul 25, 2013 · 17 comments
Closed

Comments

@volaticus
Copy link

After loading example i see only white screen on IPhone simulator 6.1. Something bad happens after registering custom NSUrlHandler. canInitWithRequest method called but GetCanonicalRequest and StartLoading never called.

Any help would be appreciated.

@welshrat
Copy link

Yes I am experiencing the same issue, none of my jsbridge events are firing with latest xamarin release, any help much appreciated as my app is now broken :-(

@volaticus
Copy link
Author

Issue gone with today's stable release (Xamarin v.6.4.0.2). Sample now works as expected.

@cdeutsch
Copy link
Owner

Thanks for the update @volaticus. Let me know if it stops working again. I'll leave this open for a day or two in case others run into it.

I'm glad Xamarin fixed it because I kind of expected I wouldn't be able to. ;)

Also, good to see some people using this library. I'm open to ideas on how to make it better.

@welshrat
Copy link

Hi crdeutch, I am still experiencing the same issue (Xamarin v.6.4.0.2), all my cdeutsch.JsBridge.AddEventListener simply never fire, I updated JSBridge and xamarin and although my app compiles ok the events simply wont fire. was all working fine up until the updates.

Any more info welcome, and yes a great library :-)

EDIT - Apologies I had not update the mt.js file, normal service has resumed.

@cdeutsch
Copy link
Owner

Hey @welshrat, I just updated mine to 6.4.0.2 and I'm not having the issue.

Double check you have 6.4.0.2. In Xamarin Studio go to the menu:
"Xamarin Studio -> About Xamarin Studio"
Click the "Show Details" button

Does the example app work for you?

Another thing to try would be to right click the project and do "Clean "

@welshrat
Copy link

Hi crdeutch, all fixed, sorry I had updated JSBridge but not replaced the mt.js file.

Many thanks and keep up the great work

@borodk
Copy link

borodk commented Jul 25, 2013

Thanks! I was having the same issue with 6.4.0.2, but updating JSBridge and mt.js fixed the problem. Great library.

@svenessar
Copy link

Hello,

great work :-)
Only one question for your example:

viewController.WebView.AddEventListener( "promptUser", delegate(FireEventData arg) {
// show a native action sheet
BeginInvokeOnMainThread (delegate {
var sheet = new UIActionSheet ( arg.Data["question"].ToString() );
sheet.AddButton ( "Yes" );
sheet.AddButton ( "No" );
sheet.CancelButtonIndex = 1;
sheet.ShowInView ( viewController.View );
});
});

How i can wait in Javascript for the clicked button result?

Best regards
Sven

@cdeutsch
Copy link
Owner

@svenessar this isn't really related to the issue, which I will be closing after this, but here's an answer.

You need to fire an event after the sheet is Clicked. So wire up the sheet "Clicked" event and in it call FireEvent.

sheet.Clicked += delegate(object s, UIButtonEventArgs e) {
    viewController.WebView.FireEvent( "sheetActionClicked", new {
        buttonIndex = e.ButtonIndex,
        extraParams = "Customize Me"
    });
};
sheet.ShowInView ( viewController.View );

You then need to handle this event in your javascript:

Mt.App.addEventListener('sheetActionClicked', function(data) {
    if (data.buttonIndex == 0) {
        console.log('button 0 clicked');
    }
    else if (data.buttonIndex == 1) {
        console.log('button 1 clicked');
    }       
});

Shoot me an email at cd@cdeutsch.com if you have more questions.

@svenessar
Copy link

Hello Christopher,

sorry for my post, you are right. It is not an issue. :- )
Thank you for your answer, but is seems that will be fired async, right?

The point is, that the JS will not wait for the answer. Is there a way to wait in JS for the answer with Native call?

My JS should be work syncron with the Native world.

Thank you so much.

Sven

Von: Christopher Deutsch [mailto:notifications@github.com]
Gesendet: Freitag, 20. September 2013 20:52
An: crdeutsch/MonoTouch-JsBridge
Cc: Sven Reißenweber
Betreff: Re: [MonoTouch-JsBridge] Seems that JsBridge not working with Xamarin.iOS Version: 6.2.7.1 (#3)

@svenessarhttps://github.com/svenessar this isn't really related to the issue, which I will be closing after this, but here's an answer.

You need to fire an event after the sheet is Clicked. So wire up the sheet "Clicked" event and in it call FireEvent.

sheet.Clicked += delegate(object s, UIButtonEventArgs e) {

viewController.WebView.FireEvent( "sheetActionClicked", new {

    buttonIndex = e.ButtonIndex,

    extraParams = "Customize Me"

});

};

sheet.ShowInView ( viewController.View );

You then need to handle this event in your javascript:

Mt.App.addEventListener('sheetActionClicked', function(data) {

if (data.buttonIndex == 0) {

    console.log('button 0 clicked');

}

else if (data.buttonIndex == 1) {

    console.log('button 1 clicked');

}

});

Shoot me an email at cd@cdeutsch.commailto:cd@cdeutsch.com if you have more questions.


Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-24832683.

@cdeutsch
Copy link
Owner

It's more "event driven" then Async.

When you "wire up" the Clicked event that code doesn't execute until the Action Sheet is clicked so that is where the "waiting" is done. So it should work.

Give it a try.

@svenessar
Copy link

Sorry it is async, maybe i am to stupid :- (

i used your example index.html:

window.onload = function(e) {
console.log( 'loaded' );

            Mt.API.info( 'log "loaded" call on native side' );

                                                           // listen for doBrowserStuff event triggered from native code.
                                                           Mt.App.addEventListener('doBrowserStuff', function(data) {

                                                                          console.log('doBrowserStuff Callback:');
                                                                          console.log(data.Message);

                                                           });

                                                           // fire doNativeStuff in native code.
                                                           Mt.App.fireEvent('doNativeStuff', {
                msg: 'Hi, this msg is from the browser.',
                extra: 'You can send more then one property back',
                answer: 42
            });

            Mt.App.addEventListener('sheetActionClicked', function(data) {
                if (data.buttonIndex == 0) {
                    console.log('button 0 clicked');
                }
                else if (data.buttonIndex == 1) {
                    console.log('button 1 clicked');
                }
            });
            console.log('finish');
                                           };

è console.log('finish'); is executed before the 'sheetActionClicked' has an answer :- (

could you help me please?
The complete JS should work syncron and wait, before execute with the next line of code, for the native result.

Thank you so much
Sven

Von: Christopher Deutsch [mailto:notifications@github.com]
Gesendet: Freitag, 20. September 2013 21:05
An: crdeutsch/MonoTouch-JsBridge
Cc: Sven Reißenweber
Betreff: Re: [MonoTouch-JsBridge] Seems that JsBridge not working with Xamarin.iOS Version: 6.2.7.1 (#3)

It's more "event driven" then Async.

When you "wire up" the Clicked event that code doesn't execute until the Action Sheet is clicked so that is where the "waiting" is done. So it should work.

Give it a try.


Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-24833958.

@cdeutsch
Copy link
Owner

If you zip up your code and email it to cd@cdeutsch.com I can take a look

@svenessar
Copy link

I modifyed your index.html

For your backround:

I use JavaScript like native code. So I call a function syncron wait for the result, take the result from the first function and call the next function with this result.

Like native

Thank you
Sven

Von: Christopher Deutsch [mailto:notifications@github.com]
Gesendet: Freitag, 20. September 2013 21:20
An: crdeutsch/MonoTouch-JsBridge
Cc: Sven Reißenweber
Betreff: Re: [MonoTouch-JsBridge] Seems that JsBridge not working with Xamarin.iOS Version: 6.2.7.1 (#3)

If you zip up and code and email it to cd@cdeutsch.commailto:cd@cdeutsch.com I can take a look


Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-24834905.

@cdeutsch
Copy link
Owner

You can't do synchronous programming between native and js. It has to be event driven.

If you send the code I can modify it to do what you want. It makes sense that "finish" is called first because it's not inside the function that handles the event.

@svenessar
Copy link

This is a running JS Code in Android:

var anvintscr_srcTbl = new recTbl(RTObj.CurrSSRecTblId);
var anvintscr_destTbl;var anvintscr_scriptName = '';
anvintscr_scriptName += anvintscr_srcTbl.GETTABLENO();anvintscr_scriptName += '_5050';
if (PAGE.EXISTPREPAREFN(anvintscr_scriptName)){anvintscr_destTbl = new recTbl(PAGE.OPENPREPARE(anvintscr_scriptName,anvintscr_srcTbl.tblID));} else {anvintscr_destTbl = new Table('Contact');}anvintscr_srcTbl.KEEPINMEMORY();
if (anvintscr_destTbl.FINDFIRST()) {PAGE.OPEN('CONTACT_CARD',anvintscr_destTbl.tblID,anvintscr_srcTbl.tblID);} else { DIALOG.ERROR('No records found.') }

in Android I use WebChromeClient with OnJsPrompt (delegated to Native), the webview wait for the prompt result and execute the next code.

Do you have any idea how I can develop this with ios?

Von: Christopher Deutsch [mailto:notifications@github.com]
Gesendet: Freitag, 20. September 2013 21:35
An: crdeutsch/MonoTouch-JsBridge
Cc: Sven Reißenweber
Betreff: Re: [MonoTouch-JsBridge] Seems that JsBridge not working with Xamarin.iOS Version: 6.2.7.1 (#3)

You can't do synchronous programming between native and js. It has to be event driven.

If you send the code I can modify it to do what you want. It makes sense that "finish" is called first because it's not inside the function that handles the event.


Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-24835843.

@cdeutsch
Copy link
Owner

Everything you want to do after the prompt results just needs to go inside the event handler function. Just like you were using jQuery and handling a button click it's the same thing.

Mt.App.addEventListener('sheetActionClicked', function(data) {
    // put the code you want to execute after the button here
});

// do NOT put the code here

Please use my email if you have more questions. There are other people subscribed to this thread on GitHub they don't need to keep getting notified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants