Esempio n. 1
0
        /// <summary>
        /// Shows the native MFMailComposeViewController to send an email.
        /// Raises MailCompleted event when completed.</summary>
        ///
        /// <param name="recipients"> An array of strings representing the email addresses of the recipients.</param>
        /// <param name="subject"> The subject of the email.</param>
        /// <param name="body"> The body of the email.</param>
        /// <param name="bodyIsHTML"> True if the body is HTML; false otherwise.</param>
        /// <param name="image"> The image to attach to the email.</param>
        /// <param name="checkServiceAvailable"> Whether to check if the service is available first.</param>
        /// <returns> True if it is able to show the native view controller; false if it cannot send email.</returns>
        public static bool Mail(string[] recipients, string subject, string body, bool bodyIsHTML, Texture2D image = null, bool checkServiceAvailable = true)
        {
            if (checkServiceAvailable && !MFMailComposeViewController.CanSendMail())
            {
                return(false);
            }

            var vc = new MFMailComposeViewController();

            if (vc.IsNil)
            {
                return(false);
            }

            vc.mailComposeDelegate = MailComposeViewControllerDelegate.instance;
            vc.SetToRecipients(recipients);
            vc.SetSubject(subject);
            vc.SetMessageBody(body, bodyIsHTML);

            if (image != null)
            {
                var nsdata = NSData.FromByteArray(image.EncodeToPNG());
                vc.AddAttachmentData(nsdata, "image/png", "image.png");
            }

            UIApplication.deviceRootViewController.PresentViewController(vc, true, null);
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the data stored on Game Center for the current match and advances the turn.
        /// Raises AdvanceTurnCompleted and AdvanceTurnFailed events for success and error completion.
        /// On iOS 5.0, it only takes one next participant, and ignores the timeout.
        /// </summary>
        /// <param name="matchData">A serialized blob of data reflecting the game-specific state for the match.</param>
        /// <param name="aMessage">A message to display reflecting the state of the match.</param>
        /// <param name="nextParticipants">An array of TurnBasedParticipant objects reflecting the order in which the players should act next.
        /// Each object in the array must be one of the objects stored in the match’s participants property.
        /// If null or not specified, it would use the next player in the order of the participants property.</param>
        /// <param name="timeout">The length of time the next player has to complete their turn; in seconds.</param>
        public void AdvanceTurn(byte[] matchData, string aMessage = null, TurnBasedParticipant[] nextParticipants = null, double timeout = 0)
        {
            if (aMessage != null)
            {
                gkTurnBasedMatch.message = aMessage;
            }

            if (nextParticipants == null)
            {
                nextParticipants = _GetNextActiveParticipants();
            }

            //hack: apple server doesn't work if it takes an array, so popping all except 1 now
            if (nextParticipants.Length > 1)
            {
                nextParticipants = new TurnBasedParticipant[] { nextParticipants[0] }
            }
            ;

            if (gkTurnBasedMatch.RespondsToSelector("endTurnWithNextParticipants:turnTimeout:matchData:completionHandler:"))
            {
                gkTurnBasedMatch.EndTurn(
                    TurnBasedParticipant.ToGKParticipants(nextParticipants),
                    timeout, NSData.FromByteArray(matchData),
                    _CreateCompleteFunction(_advanceTurnCompletedHandlers, _advanceTurnFailedHandlers));
            }
            else
            {
                gkTurnBasedMatch.EndTurn(
                    TurnBasedParticipant.ToGKParticipants(nextParticipants)[0],
                    NSData.FromByteArray(matchData),
                    _CreateCompleteFunction(_advanceTurnCompletedHandlers, _advanceTurnFailedHandlers));
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Saves the merged data.
 /// Raises SaveMergedMatchDataCompleted and SaveMergedMatchDataFailed events after completion.
 /// Available in iOS 7.0 and later.
 /// </summary>
 /// <param name="matchData">The new match data.</param>
 /// <param name="exchanges">An array of GKTurnBasedExchange objects that contains the resolved exchanges.</param>
 public void SaveMergedMatchData(byte[] matchData, GKTurnBasedExchange[] exchanges)
 {
     gkTurnBasedMatch.SaveMergedMatchData(
         NSData.FromByteArray(matchData),
         exchanges,
         _CreateCompleteFunction(_saveMergedMatchDataCompletedHandlers, _saveMergedMatchDataFailedHandlers));
 }
Esempio n. 4
0
 /// <summary>
 /// Sends an exchange request to one or more participants.
 /// Raises ExchangeSent event after completion.  Check the error property of the event for errors.
 /// Available in iOS 7.0 and later.
 /// </summary>
 /// <param name="participants">The participants to receive the exchange.</param>
 /// <param name="data">Data.</param>
 /// <param name="messageKey">The location of the alert message string in the Localizable.strings file for the current localization.</param>
 /// <param name="messageArgs">An array of strings to be substituted using the format string.</param>
 /// <param name="timeout">The length of time the next player has to complete their turn.</param>
 public void SendExchange(TurnBasedParticipant[] participants, byte[] data, string messageKey, string[] messageArgs, double timeout)
 {
     gkTurnBasedMatch.SendExchangeToParticipants(
         TurnBasedParticipant.ToGKParticipants(participants),
         NSData.FromByteArray(data),
         messageKey,
         messageArgs,
         timeout,
         _SendExchangeCompleteHander);
 }
Esempio n. 5
0
        /// <summary>
        /// Updates the data stored on Game Center for the current match but does not advance the turn.
        /// Raises SaveTurnCompleted and SaveTurnFailed events for success and error completion.
        /// Available in iOS 6.0 and later.
        /// </summary>
        /// <param name="matchData">A serialized blob of data reflecting the game-specific state for the match.</param>
        /// <param name="aMessage">A message to display reflecting the state of the match.</param>
        public void SaveTurn(byte[] matchData, string aMessage = null)
        {
            if (aMessage != null)
            {
                gkTurnBasedMatch.message = aMessage;
            }

            gkTurnBasedMatch.SaveCurrentTurn(NSData.FromByteArray(matchData),
                                             _CreateCompleteFunction(_saveTurnCompletedHandlers, _saveTurnFailedHandlers));
        }
Esempio n. 6
0
        /// <summary>
        /// Ends the match. Raises EndMatchCompleted and EndMatchFailed events for success and error completion.
        /// </summary>
        /// <param name="matchData">A serialized blob of data reflecting the end state for the match.</param>
        /// <param name="aMessage">A message to display reflecting the state of the match.</param>
        public void EndMatch(byte[] matchData, string aMessage = null)
        {
            if (aMessage != null)
            {
                gkTurnBasedMatch.message = aMessage;
            }

            gkTurnBasedMatch.EndMatchInTurn(NSData.FromByteArray(matchData),
                                            _CreateCompleteFunction(_endMatchCompletedHandlers, _endMatchFailedHandlers));
        }
Esempio n. 7
0
    private void SendData(string text)
    {
        if (_session == null)
        {
            Log("Not connected.");
            return;
        }

        NSData data = NSData.FromByteArray(text.ToStraightBytes());

        _session.SendData(data, new object[] { _peerId }, MCSessionSendDataMode.Reliable, null);
    }
Esempio n. 8
0
        /// <summary>
        /// Sends data to all players in the match.
        /// </summary>
        /// <returns>The error code; 0 means successful.</returns>
        /// <param name="data">A byte array representing the data to be sent.</param>
        /// <param name="reliable">Whether to send it using reliable method; using false for this sends it faster but does not guarantee delivery or the order of delivering multiple data packets.</param>
        public int SendDataToAll(byte[] data, bool reliable)
        {
            int code  = 0;
            var error = new NSError();

            if (!gkMatch.SendDataToAllPlayers(NSData.FromByteArray(data),
                                              reliable ? GKMatchSendDataMode.Reliable : GKMatchSendDataMode.Unreliable,
                                              error))
            {
                code = error.Code();
            }

            error = null;
            return(code);
        }