Daddoon / BlazorMobile

Create full C# driven hybrid-apps for iOS, Android, UWP & Desktop with Blazor!
MIT License
413 stars 55 forks source link

[Bug] Sample Project BlazorMobile does not show alert via XamarinBridge #226

Open DanGould opened 3 years ago

DanGould commented 3 years ago

I am experiencing this behavior across iPhone 8 Plus, Android Sumulator of pixel_2_pie_9.0 and Electron.NET. The Native XamarinBridge behavior isn't firing at all on any platform.

Having followed the readme, I'm not sure what's missing for initialization as the service seems to work fine. Maybe it's because it's running as a server on device rather than WASM? I'm not sure.

Love the idea of using this project for a native app, but native functionality like using the device HSM is vital to my use case.

Daddoon commented 3 years ago

Normaly it should works out of the box.

The application on the Device will be in WASM mode (except on Electron where you have the choice with one specific flag).

Also, note that there will be an upcoming release this month (i think) as i figured that in some cases, the WebSocket connection to native seems to break and doesn't auto-reconnect automatically. I don't know yet if this is the server part breaking and restarting or a WebSocket connection conflict with Blazor somehow, as Blazor WASM has now it's own WebSocket connection for debug with Visual Studio since some updates of Microsoft.

Can you post your build log ? Can you post the browser console too when launching your app ? You may access it on every platform with debugging tools, it's just different for each platform (Android => WebIDE with Firefox 67, iOS => Safari from a Mac).

You can take a look at this part: https://github.com/Daddoon/BlazorMobile#device-remote-debugging--debugging-from-net-core-30

Just to finish, on the other end, it seem that Microsoft Mobile Blazor Bindings may now support Hybrid Blazor app in addition to the XAML additions they have created, and that the browser C# process is running natively instead of WASM during it's lifetime. I just don't have yet taken the time to take a look at this new feature, and seen if there is some differences, limitations or else, but it can be also an alternative to take look at.

DanGould commented 3 years ago

Are you having this issue while doing some kind of remote debugging ?

The same behavior happens across remote or local debug

Do you have this issue when deploying in release mode on a device ?

yes, I do. As soon as I click the "BlazorMobile" link the nav just closes. I never see the page with BlazorMobile heading and an alert does not show. This part of the code is not being reached at all according to the debugger.

The same behavior occurs when I put the relevant code ⬇️ on any page. Just can't nav to that page.

@code {

    async void ShowPlatform()
    {
        await XamarinBridge.DisplayAlert("Platform identity", $"Current platform is {BlazorDevice.RuntimePlatform}", "Great!");
    }
}

build log via VS Mac: https://pastebin.com/RdAA5BjF Application Output in VS Mac: https://pastebin.com/upSm92Ev

Both from Android Emulator

I'll have to check out Microsoft Mobile Blazor Bindings. I wonder how the performance might differ. Really I want to build the interface with HTML & CSS Cause then it's way easier to directly involve designers. Thank you!

Daddoon commented 3 years ago

This may remind me this issue .

Thanks for the log and application output, but the Browser log of your device is missing. I never tested BlazorMobile directly on Mac, so i don't know if there is some possible issues.

Do you have any repro project i can try to open and see ? It sound weird that i doesn't work with stock template. Also what is your .NET Core version ? Did you have tested to build and deploy from a Windows machine ? (if possible)

arivera12 commented 3 years ago

Yup, I was just gonna make a new issue regarding on this just now.

There seems issues with iOS platform when initializing the services.

I integrated secure storage from xamarin essentials for all platforms, SecureStorage never get's initialized on iOS platform.

It worked properly on android emulator and a real device.

But never worked neither on iOS emulator or real iOS device.

https://docs.microsoft.com/en-us/xamarin/essentials/secure-storage?context=xamarin/xamarin-forms

Take note also I experienced a random behavior that for some reason sometime the xamarin services get's cached by the ProxyInterface when generating the proxy methods that are used for native communication.

I ended commenting the service -> rebuild -> uncomment -> rebuild to recreate the proxy method files

Daddoon commented 3 years ago

@arivera12 Please talk about this in the issue i just opened from your message.

Your issue with SecureStorage seem's weird, i doubt that BlazorMobile has something to do with that, but feel free to send a repro on the other issue #227 .

I don't understand exactly by what you are talking about services cached by ProxyInterface. If it's about code change that seems to not be reflected in the build from ProxyInterface, take note that the Blazor code parts for this are autogenerated at build in order to create the class implementation needed for doing all the interop "magically" (Method signature, and else).

Autogenerated code at build for this is present in the obj folder of your Blazor project, i don't remember the exact subfolder, but this mean that if you think the code is outdated for some reason, feel free to completly delete this obj folder, then rebuild.

I still have theses kind of issue on old ASP.NET MVC 4 projects, maybe not for the same reason, but forcing the obj folder to be cleaned always fix the integrity problem.