Apple Watch设备因Sandbox崩溃而崩溃拒绝(1)网络出站 [英] Apple Watch Device crashing with SandboxViolation deny(1) network-outbound
问题描述
拨打网络电话时,Apple Watch出现问题.
Im having an issue on the Apple Watch when making network calls.
它在模拟器上可以正常工作,但是当部署到设备上时,我会在设备日志中看到这一点:
It works fine on the simulator but when deployed to the device I see this in the device logs:
MyAppleWatch内核(沙盒)[0]:沙盒违反:MyWatchApp(203)拒绝(1)网络出站/private/var/run/mDNSResponder
MyAppleWatch kernel(Sandbox)[0] : SandboxViolation: MyWatchApp(203) deny(1) network-outbound /private/var/run/mDNSResponder
进行调用的代码是使用refit完成的,并且可以在模拟器上运行,因此我想可能不是原因,但如有必要,我会发布它.
The code for making the call is done using refit and works on the simulator so I would imagine it is not the cause but I will post it if necessary.
我已经在WatchExtensionApp的Info.plist中设置了这些值(而不是在WatchApp中将它们设置为这些键)
I have set these values in the Info.plist of the WatchExtensionApp (and not set them in the WatchApp as these keys )
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>my.domain.com</key>
<dict>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
我将WatchApp和WatchExtensionApp设置为:
I set the WatchApp and WatchExtensionApp to:
接下来要尝试的内容有点不知所措.任何帮助将不胜感激.
Just at a bit of loss as to what to try next. Any help would be greatly appreciated.
推荐答案
好,我可以正常使用了,首先我将Info.plist
更改为:
Ok I got it working, Firstly I changed my Info.plist
to:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>my.domain.com</key>
<dict>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
我不得不将对我的所有网络呼叫更改为NSUrlSession
,而不是使用Refit + HttpClient.因此,我认为HttpClient
中存在watchOS不喜欢的东西,或者watchos仅与NSUrlSession
一起工作.无论如何,这里是我的一个电话的样本:
I had to change all my network calls to us NSUrlSession
rather than using Refit + HttpClient. So I assume there is something in the HttpClient
that watchOS doesn't like or watchos only works with NSUrlSession
. Anyway here is a sample of one of my calls:
public async Task<HttpResponse> MakeCall(NSMutableUrlRequest request)
{
var result = new HttpResponse();
var config = NSUrlSessionConfiguration.DefaultSessionConfiguration;
var session = NSUrlSession.FromConfiguration(config);
var resultUser = await session.CreateDataTaskAsync(request);
var response = resultUser.Response as NSHttpUrlResponse;
if (response != null)
{
result.StatusCode = (int)response.StatusCode;
result.Content = NSString.FromData(resultUser.Data, NSStringEncoding.UTF8).ToString();
}
return result;
}
public async Task<HttpResponse> GetStuffWithParameter(string parameter, string authorization)
{
var url = new NSUrl($"https://www.domain.com/api/stuff/{parameter}");
var header = new NSMutableDictionary();
header.SetValueForKey(new NSString(authorization), new NSString("Authorization"));
header.SetValueForKey(new NSString("application/json"), new NSString("Content-Type"));
var request = new NSMutableUrlRequest(url)
{
Headers = header,
HttpMethod = "GET"
};
return await MakeCall(request);
}
public class HttpResponse
{
public int StatusCode { get; set; }
public object Content { get; set; }
}
希望这会有所帮助.
这篇关于Apple Watch设备因Sandbox崩溃而崩溃拒绝(1)网络出站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!