コード例 #1
0
        public async override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            dataSource                   = new MessagesDataSource();
            tableView.Source             = dataSource;
            tableView.RowHeight          = UITableView.AutomaticDimension;
            tableView.EstimatedRowHeight = 70;

            var token = await GetToken();

            this.NavigationItem.Prompt = $"Logged in as {identity}";
            var accessManager = TwilioAccessManager.Create(token, this);

            client = TwilioIPMessagingClient.Create(accessManager, this);

            client.GetChannelsList((result, channels) =>
            {
                generalChannel = channels.GetChannelWithUniqueName("general");

                if (generalChannel != null)
                {
                    generalChannel.Join(r =>
                    {
                        Console.WriteLine("successfully joined general channel!");
                    });
                }
                else
                {
                    var options = new NSDictionary("TWMChannelOptionFriendlyName", "General Chat Channel", "TWMChannelOptionType", 0);

                    channels.CreateChannel(options, (creationResult, channel) =>
                    {
                        if (creationResult.IsSuccessful())
                        {
                            generalChannel = channel;
                            generalChannel.Join(r =>
                            {
                                generalChannel.SetUniqueName("general", res => { });
                            });
                        }
                    });
                }
            });

            NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, KeyboardWillShow);
            NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.DidShowNotification, KeyboardDidShow);
            NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, KeyboardWillHide);

            this.View.AddGestureRecognizer(new UITapGestureRecognizer(() =>
            {
                this.messageTextField.ResignFirstResponder();
            }));

            this.messageTextField.Delegate = this;
        }
コード例 #2
0
        public async Task <bool> InitializeAsync()
        {
            var task = new TaskCompletionSource <bool>();

            try
            {
                var token = await TwilioHelper.GetTokenAsync();

                var accessManager = TwilioAccessManager.Create(token, this);
                client = TwilioIPMessagingClient.Create(accessManager, this);

                client.GetChannelsList((result, channels) =>
                {
                    generalChannel = channels.GetChannelWithUniqueName("general");
                    if (generalChannel != null)
                    {
                        generalChannel.Join(r =>
                        {
                            Console.WriteLine("successfully joined general channel!");
                            task.SetResult(true);
                        });
                    }
                    else
                    {
                        var options = new NSDictionary("TWMChannelOptionFriendlyName", "General Chat Channel", "TWMChannelOptionType", 0);

                        channels.CreateChannel(options, (creationResult, channel) =>
                        {
                            if (creationResult.IsSuccessful())
                            {
                                generalChannel = channel;
                                generalChannel.Join(r =>
                                {
                                    generalChannel.SetUniqueName("general", res => { });
                                    task.SetResult(true);
                                });
                            }
                            else
                            {
                                task.SetResult(false);
                            }
                        });
                    }
                });
            }
            catch
            {
                return(false);
            }


            return(await task.Task.ConfigureAwait(false));
        }