Esempio n. 1
0
        /// <summary>
        /// Send  a piece of message data if the session is activated and update UI with the command status.
        /// </summary>
        public static void SendMessageData(NSData messageData)
        {
            var commandStatus = new CommandStatus(Command.SendMessageData, Phrase.Sent)
            {
                TimedColor = TimedColor.Create(messageData)
            };

            if (WCSession.DefaultSession.ActivationState == WCSessionActivationState.Activated)
            {
                WCSession.DefaultSession.SendMessage(messageData, (replyData) =>
                {
                    commandStatus.Phrase     = Phrase.Replied;
                    commandStatus.TimedColor = TimedColor.Create(replyData);
                    PostNotificationOnMainQueueAsync(NotificationName.DataDidFlow, commandStatus);
                }, (error) =>
                {
                    commandStatus.Phrase       = Phrase.Failed;
                    commandStatus.ErrorMessage = error.LocalizedDescription;
                    PostNotificationOnMainQueueAsync(NotificationName.DataDidFlow, commandStatus);
                });

                PostNotificationOnMainQueueAsync(NotificationName.DataDidFlow, commandStatus);
            }
            else
            {
                HandleSessionUnactivated(commandStatus);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Called when a piece of message data is received and the peer doesn't need a respons
        /// </summary>
        public override void DidReceiveMessageData(WCSession session, NSData messageData)
        {
            var commandStatus = new CommandStatus(Command.SendMessageData, Phrase.Received)
            {
                TimedColor = TimedColor.Create(messageData)
            };

            this.PostNotificationOnMainQueueAsync(NotificationName.DataDidFlow, commandStatus);
        }