step-up-labs / firebase-database-dotnet

C# library for Firebase Realtime Database.
MIT License
671 stars 170 forks source link

Can't use Realtime streaming in Xamarin IOS #54

Closed cuong95nddev closed 7 years ago

cuong95nddev commented 7 years ago

`using Firebase.Database; using Firebase.Database.Query; using System; using System.Threading.Tasks; using System.Reactive.Linq; using UIKit; using System.Threading;

namespace Chat { public partial class ViewController : UIViewController { private const String CHAT_KEY = "chat";

    String authSecret = "RxIsctLdNZeV110WJ6PP0QtOPIwj9R1Fm5Tn9N3G";
    String basePath = "https://chat-c642c.firebaseio.com/";

    FirebaseClient firebaseClient;
    ChildQuery childChat;

    private String name = "ios";

    public ViewController(IntPtr handle) : base(handle)
    {

    }

    async void init()
    {
        this.firebaseClient = new FirebaseClient(
          this.basePath,
          new FirebaseOptions
          {
              AuthTokenAsyncFactory = () => Task.FromResult(this.authSecret)
          });

        this.childChat = this.firebaseClient.Child(CHAT_KEY);

        var observable = childChat.AsObservable<InboundMessage>();
        var subscription = observable
            .Where(f => !string.IsNullOrEmpty(f.Key)) // you get empty Key when there are no data on the server for specified node
            .Subscribe(f => show("ssss"));

    }

    void show(String data)
    {
        UIAlertView alert = new UIAlertView()
        {
            Title = "alert title",
            Message = data
        };
        alert.AddButton("OK");
        alert.Show();
    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        // Perform any additional setup after loading the view, typically from a nib.

        this.init();

    }

    public override void DidReceiveMemoryWarning()
    {
        base.DidReceiveMemoryWarning();
        // Release any cached data, images, etc that aren't in use.
    }

    partial void BtnTest_TouchUpInside(UIButton sender)
    {
        this.push();
    }

    async void push()
    {
        await this.childChat.PostAsync(new OutboundMessage { Author = name, Content = "ahaha" });
    }
}

}`

nothing happened when the data change. Thank.

cuong95nddev commented 7 years ago

Fixed by using xamarin on vmware instance of mac host