Unity3D www.error 返回 "cannot connect to destination host" 并在 iOS 上崩溃
Unity3D www.error returning "cannot connect to destination host" and crash on iOS
在使用 WWWForm 进行 WWW post 请求期间,我在 IOS 上遇到了崩溃。这在 Android 和 UnityEditor 本身上运行良好,但只要执行 www 行,它就会在 iOS 上崩溃。
我是否遗漏了导致 iOS 崩溃的任何内容?或者是否有任何特定原因导致此问题? (我对这个领域很陌生,所以任何建议、解决方案或建议都将不胜感激。)
我试图用这段代码向 trello 添加一张新卡片。 (密钥和令牌是从 Trello 本身获得的。)这是执行请求的代码:
private const string cardBaseUrl = "https://api.trello.com/1/cards/";
public IEnumerator UploadCardCO(Card card)
{
WWWForm post = new WWWForm();
post.AddField("name", card.name);
post.AddField("desc", card.desc);
post.AddField("pos", card.pos);
post.AddField("due", card.due);
post.AddField("idList", card.idList);
WWW www = new WWW(cardBaseUrl + "?" + "key=" + key + "&token=" + token, post);
yield return www;
}
public IEnumerator SendReportCO( Card card )
{
yield return this.StartCoroutine( trello.UploadCardRoutine( card ) );
}
这是来自 XCode 的崩溃日志:
2020-08-24 20:45:04.589031+0800 MYAPP[3226:2915180] Task <E65D3D4B-4A00-425C-8316-6C71D2DAFD9F>.<1> HTTP load failed, 564/1774 bytes (error code: -1005 [4:-4])
2020-08-24 20:45:04.589381+0800 MYAPP[3226:2915180] Task <E65D3D4B-4A00-425C-8316-6C71D2DAFD9F>.<1> HTTP load failed, 564/1774 bytes (error code: -1005 [4:-4])
2020-08-24 20:45:04.591199+0800 MYAPP[3226:2915221] Task <E65D3D4B-4A00-425C-8316-6C71D2DAFD9F>.<1> finished with error [-1005] Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=-4, NSUnderlyingError=0x281ca8de0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={NSErrorPeerAddressKey=<CFData 0x2830ec960 [0x1c82af728]>{length = 16, capacity = 16, bytes = 0x100201bb1288d6140000000000000000}, _kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalUploadTask <E65D3D4B-4A00-425C-8316-6C71D2DAFD9F>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalUploadTask <E65D3D4B-4A00-425C-8316-6C71D2DAFD9F>.<1>"
), NSLocalizedDescription=The network connection was lost., NSErrorFailingURLStringKey=https://api.trello.com/1/cards/?key="KEY"&token="TOKEN", NSErrorFailingURLKey=https://api.trello.com/1/cards/?key="KEY"&token="TOKEN", _kCFStreamErrorDomainKey=4}
Uploading Crash Report
TrelloException: Could not upload new card to Trello: Cannot connect to destination host
at Trello.CheckWwwStatus (System.String errorMessage, UnityEngine.WWW www) [0x00000] in <00000000000000000000000000000000>:0
at Trello+<UploadCardCO>d__27.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0
(Filename: currently not available on il2cpp Line: -1)
Uploading Crash Report
TrelloException: Could not upload new card to Trello: Cannot connect to destination host
at Trello.CheckWwwStatus (System.String errorMessage, UnityEngine.WWW www) [0x00000] in <00000000000000000000000000000000>:0
at Trello+<UploadCardCO>d__27.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0
UnityEngine.UnhandledExceptionHandler:PrintException(String, Exception)
UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)
System.UnhandledExceptionEventHandler:Invoke(Object, UnhandledExceptionEventArgs)
(Filename: currently not available on il2cpp Line: -1)
通过重构代码修复了崩溃。以前我不知道在 iOS 上抛出异常会导致崩溃问题。但是,我在 iOS13.5.1 问题上仍然有相同的 UnityWebRequest.error return“无法连接到目标主机”问题。我已经打开了一个专注于这个领域的新线程。这是 link:
Unity3D UnityWebRequest.error return "cannot connect to destination host" on iOS13.5.1
在使用 WWWForm 进行 WWW post 请求期间,我在 IOS 上遇到了崩溃。这在 Android 和 UnityEditor 本身上运行良好,但只要执行 www 行,它就会在 iOS 上崩溃。
我是否遗漏了导致 iOS 崩溃的任何内容?或者是否有任何特定原因导致此问题? (我对这个领域很陌生,所以任何建议、解决方案或建议都将不胜感激。)
我试图用这段代码向 trello 添加一张新卡片。 (密钥和令牌是从 Trello 本身获得的。)这是执行请求的代码:
private const string cardBaseUrl = "https://api.trello.com/1/cards/";
public IEnumerator UploadCardCO(Card card)
{
WWWForm post = new WWWForm();
post.AddField("name", card.name);
post.AddField("desc", card.desc);
post.AddField("pos", card.pos);
post.AddField("due", card.due);
post.AddField("idList", card.idList);
WWW www = new WWW(cardBaseUrl + "?" + "key=" + key + "&token=" + token, post);
yield return www;
}
public IEnumerator SendReportCO( Card card )
{
yield return this.StartCoroutine( trello.UploadCardRoutine( card ) );
}
这是来自 XCode 的崩溃日志:
2020-08-24 20:45:04.589031+0800 MYAPP[3226:2915180] Task <E65D3D4B-4A00-425C-8316-6C71D2DAFD9F>.<1> HTTP load failed, 564/1774 bytes (error code: -1005 [4:-4])
2020-08-24 20:45:04.589381+0800 MYAPP[3226:2915180] Task <E65D3D4B-4A00-425C-8316-6C71D2DAFD9F>.<1> HTTP load failed, 564/1774 bytes (error code: -1005 [4:-4])
2020-08-24 20:45:04.591199+0800 MYAPP[3226:2915221] Task <E65D3D4B-4A00-425C-8316-6C71D2DAFD9F>.<1> finished with error [-1005] Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=-4, NSUnderlyingError=0x281ca8de0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={NSErrorPeerAddressKey=<CFData 0x2830ec960 [0x1c82af728]>{length = 16, capacity = 16, bytes = 0x100201bb1288d6140000000000000000}, _kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalUploadTask <E65D3D4B-4A00-425C-8316-6C71D2DAFD9F>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalUploadTask <E65D3D4B-4A00-425C-8316-6C71D2DAFD9F>.<1>"
), NSLocalizedDescription=The network connection was lost., NSErrorFailingURLStringKey=https://api.trello.com/1/cards/?key="KEY"&token="TOKEN", NSErrorFailingURLKey=https://api.trello.com/1/cards/?key="KEY"&token="TOKEN", _kCFStreamErrorDomainKey=4}
Uploading Crash Report
TrelloException: Could not upload new card to Trello: Cannot connect to destination host
at Trello.CheckWwwStatus (System.String errorMessage, UnityEngine.WWW www) [0x00000] in <00000000000000000000000000000000>:0
at Trello+<UploadCardCO>d__27.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0
(Filename: currently not available on il2cpp Line: -1)
Uploading Crash Report
TrelloException: Could not upload new card to Trello: Cannot connect to destination host
at Trello.CheckWwwStatus (System.String errorMessage, UnityEngine.WWW www) [0x00000] in <00000000000000000000000000000000>:0
at Trello+<UploadCardCO>d__27.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0
UnityEngine.UnhandledExceptionHandler:PrintException(String, Exception)
UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)
System.UnhandledExceptionEventHandler:Invoke(Object, UnhandledExceptionEventArgs)
(Filename: currently not available on il2cpp Line: -1)
通过重构代码修复了崩溃。以前我不知道在 iOS 上抛出异常会导致崩溃问题。但是,我在 iOS13.5.1 问题上仍然有相同的 UnityWebRequest.error return“无法连接到目标主机”问题。我已经打开了一个专注于这个领域的新线程。这是 link: Unity3D UnityWebRequest.error return "cannot connect to destination host" on iOS13.5.1