pusher / pusher-websocket-dotnet

Pusher Channels Client Library for .NET
MIT License
111 stars 113 forks source link

Error when subscribing to channels from ios platform app #143

Closed RenataSaenz closed 1 year ago

RenataSaenz commented 1 year ago

I'm have the following 2 errors when using the app in ios:

1- Error: ERROR An unexpected error was detected when performing the operation 'Subscribe to events': System.Reflection.Emit.DynamicMethod::.ctor

PusherClient.ErrorEventHandler:Invoke(Object, PusherException) PusherClient.Pusher:InvokeErrorHandler(PusherException) System.Threading.ThreadPoolWorkQueue:Dispatch()

2- Error: ERROR Subscribe failed for channel 'events': One or more errors occurred.

PusherClient.ErrorEventHandler:Invoke(Object, PusherException) PusherClient.Pusher:InvokeErrorHandler(PusherException) System.Threading.ThreadPoolWorkQueue:Dispatch()

The configuration says i should set the Scripting Runtime Version to .NET 4.x Equivalent. But this is not supported by ios. What should i do?

benw-pusher commented 1 year ago

could you confirm if this is using the .net MAUI framework? Are you able to share the code used when these errors are encountered?

RenataSaenz commented 1 year ago

How do I confirm if this is using the .net MAUI framework? Sorry, I'm new with the implementation of all related to .Net and Pusher. I'm using the PusherClient library but not the service hosted by pusher. When I run the game in windows app or unity editor, it works well. But, when I try the app in IOS it shows the error I listed above. My code where I try to connect is the following:

using PusherClient; using System.Net.Http; using System; using UnityEngine; using System.Collections.Generic;

private void Start()
{

    Connect();
}
public async void Connect()
{
    try
    {
        Pusher pusher = new Pusher("123456", new PusherOptions
        {
            Cluster = "mt1",
           Host = "-------",

        });

        pusher.Error += OnPusherOnError;
        pusher.ConnectionStateChanged += PusherOnConnectionStateChanged;
        pusher.Connected += PusherOnConnected;
        pusher.Subscribed += OnChannelOnSubscribed;
        pusher.Disconnected += OnDisconnected;
        //Connecting to web socket
        await pusher.ConnectAsync().ConfigureAwait(false);

        //Subscribing to channel
        Channel channel = await pusher.SubscribeAsync("events").ConfigureAwait(false);

        if (channel.IsSubscribed)
        {
            //Debug.Log("SUBSCRIBE");
            //Binding to an event
            channel.Bind("App\\Events\\RealTimeEvent", (PusherEvent eventResponse) =>
            {
                Debug.Log(eventResponse.Data);
            });
            channel.Bind("App\\Events\\JugadorTorneoEvent", (PusherEvent eventResponse) =>
            {

              string message = eventResponse.Data;
                Data data = JsonUtility.FromJson<Data>(message);
                dataTorneoEvent = JsonUtility.FromJson<MyEventData>(data.message);
                JugadorTorneoEvent();
            });
             channel.Bind("App\\Events\\EquipoTorneoEvent", (PusherEvent eventResponse) =>
             {
                 //EVENTO DE EQUIPO COMPLETO
                 string message = eventResponse.Data;
                 Data data = JsonUtility.FromJson<Data>(message);
                 equipoTorneoEvent = JsonUtility.FromJson<MyEventData>(data.message);

                 EquipoTorneoEvent();

             });
        }
        else
            Debug.Log("NO SUBSCRIBED");
    }
    catch (Exception)
    {
        Debug.Log("An exception occurred.");
    }
}
benw-pusher commented 1 year ago

We aren't able to provide support for scenarios encountered when not using the official Pusher Channels service.