5

I have an app built in Unity and setup to be released on the Mac App Store that has networking tasks that work just fine in an OS X build thats not for the app store but once a build that requires App store validation / codesign is made the networking fails. The app and the build process worked not that long ago but now fails.

I'm including networking permissions in the entitlements and I'm not seeing any trace of a sandbox error in the system Console. The in app purchase networking calls are succeeding, but if I check traffic for anything else in the terminal no data moves in or out.

So I was wondering if anyone had any ideas on what might be causing this or further tests I could use to figure out what the problem might be.

4
  • what plugins do you use? and what frameworks do you add in xcode? what are the networking tasks? simple json queries or sockets or what? please elaborate to increase the chance of getting support, and make it easier for us to help you out.
    – DeyaEldeen
    Mar 29, 2016 at 9:31
  • The only plugin is the Unity IAP, no frameworks added via Xcode (not using Xcode at all really). Networking I'm trying to connect to Parse but I've also tried simply WWW calls to test sites and nothing is getting through. Apr 7, 2016 at 5:13
  • @AlexTheMighty I'm having the same issue using Unity 5.3.4p1. Did you ever find a solution? May 10, 2016 at 14:10
  • @AndrewGarrison sadly I have not yet. I've figured out the issue is somehow related to HTTPS failing but I'm not sure what exactly happens to change a working OS X build to a failed Mac App Store one. May 10, 2016 at 21:10

1 Answer 1

0

I never figured out what was wrong Unity's WWW class, but I was able to get around the issue using the System.Net.WebClient class. I implemented a simple wrapper that has a similar interface to Unity's WWW class. Here's the code I used:

using System;
using System.Net;
using System.Net.Security;
using System.Text;

/// <summary>
/// Web request using the WebClient class.
/// </summary>
/// <seealso cref="Assets.Scripts.WebRequest" />
internal class WebRequest
{
   /// <summary>
   /// The web client.
   /// </summary>
   private WebClient _client;

   /// <summary>
   /// The error message.
   /// </summary>
   private string _error;

   /// <summary>
   /// The is done flag.
   /// </summary>
   private bool _isDone;

   /// <summary>
   /// The progress.
   /// </summary>
   private float _progress;

   /// <summary>
   /// The text.
   /// </summary>
   private string _text;

   /// <summary>
   /// Initializes a new instance of the <see cref="WebRequest"/> class.
   /// </summary>
   /// <param name="url">The URL.</param>
   public WebRequest(string url)
   {
      this._client = new System.Net.WebClient();
      this._client.DownloadProgressChanged += this.WebClientProgressChanged;
      this._client.DownloadStringCompleted += this.WebClientDownloadCompleted;
      this._client.DownloadStringAsync(new Uri(url));
   }

   /// <summary>
   /// Initializes a new instance of the <see cref="WebRequestDotNet"/> class.
   /// </summary>
   /// <param name="url">The URL.</param>
   /// <param name="form">The form.</param>
   public WebRequest(string url, UnityEngine.WWWForm form)
   {
      this._client = new System.Net.WebClient();
      this._client.UploadProgressChanged += this.WebClientUploadProgressChanged;
      this._client.UploadDataCompleted += this.WebClientUploadCompleted;

      this._client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

      // Try to get the header from the Unity form
      foreach (var header in form.headers)
      {
         const string ContentType = "Content-Type";
         if (header.Key == ContentType)
         {
            string contentType = header.Value;
            this._client.Headers.Remove(ContentType);
            this._client.Headers[ContentType] = contentType;
         }
      }

      this._client.UploadDataAsync(new Uri(url), form.data);
   }

   /// <summary>
   /// Gets the error message. Returns null if there is no error.
   /// </summary>
   /// <value>
   /// The error message.
   /// </value>
   public string Error
   {
      get
      {
         return this._error;
      }
   }

   /// <summary>
   /// Gets a value indicating whether this request is done.
   /// </summary>
   /// <value>
   ///   <c>true</c> if this instance is done; otherwise, <c>false</c>.
   /// </value>
   public bool IsDone
   {
      get
      {
         return this._isDone;
      }
   }

   /// <summary>
   /// Gets the progress, 0 to 1.
   /// </summary>
   /// <value>
   /// The progress.
   /// </value>
   public float Progress
   {
      get
      {
         return this._progress / 100.0f;
      }
   }

   /// <summary>
   /// Gets the resulting text.
   /// </summary>
   /// <value>
   /// The text.
   /// </value>
   public string Text
   {
      get
      {
         return this._text;
      }
   }

   /// <summary>
   /// Called when the download is complete.
   /// </summary>
   /// <param name="sender">The sender.</param>
   /// <param name="e">The <see cref="DownloadStringCompletedEventArgs"/> instance containing the event data.</param>
   private void WebClientDownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
   {
      if (e.Error != null)
      {
         this._error = e.Error.ToString();
      }
      else
      {
         this._text = e.Result;
      }

      this._isDone = true;
   }

   /// <summary>
   /// Called when the progress changes.
   /// </summary>
   /// <param name="sender">The sender.</param>
   /// <param name="e">The <see cref="DownloadProgressChangedEventArgs"/> instance containing the event data.</param>
   private void WebClientProgressChanged(object sender, DownloadProgressChangedEventArgs e)
   {
      this._progress += e.ProgressPercentage;
   }

   /// <summary>
   /// Called when the upload is complete.
   /// </summary>
   /// <param name="sender">The sender.</param>
   /// <param name="e">The <see cref="UploadValuesCompletedEventArgs"/> instance containing the event data.</param>
   private void WebClientUploadCompleted(object sender, UploadDataCompletedEventArgs e)
   {
      if (e.Error != null)
      {
         this._error = e.Error.ToString();
      }
      else
      {
         this._text = Encoding.UTF8.GetString(e.Result);
      }

      this._isDone = true;
   }

   /// <summary>
   /// Called when the upload progress changes.
   /// </summary>
   /// <param name="sender">The sender.</param>
   /// <param name="e">The <see cref="UploadProgressChangedEventArgs"/> instance containing the event data.</param>
   private void WebClientUploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
   {
      this._progress += e.ProgressPercentage;
   }
}

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.