aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/csharp/HelloworldXamarin/iOS/ViewController.cs
blob: 33bb4a00e26f72b1a6443ab35709bd13e4212e2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using Grpc.Core;
using Helloworld;

using UIKit;

namespace HelloworldXamarin.iOS
{
    public partial class ViewController : UIViewController
    {
        int count = 1;

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

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            Button.AccessibilityIdentifier = "myButton";
            Button.TouchUpInside += delegate
            {
                var title = SayHello();
                Button.SetTitle(title, UIControlState.Normal);
            };
        }

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

            private string SayHello()
            {

              // use loopback on host machine: https://developer.android.com/studio/run/emulator-networking
              Channel channel = new Channel("10.0.2.2:50051", ChannelCredentials.Insecure);

              var client = new Greeter.GreeterClient(channel);
              string user = "Xamarin";

              var reply = client.SayHello(new HelloRequest { Name = user });

              channel.ShutdownAsync().Wait();

              return "Greeting: " + reply.Message;
            }
    }
}