Apple Watch 设备因 SandboxViolation deny(1) 网络出站而崩溃 [英] Apple Watch Device crashing with SandboxViolation deny(1) network-outbound

查看:19
本文介绍了Apple Watch 设备因 SandboxViolation deny(1) 网络出站而崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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 kernel(Sandbox)[0] : SandboxViolation: MyWatchApp(203) deny(1) network-outbound/private/var/run/mDNSResponder

MyAppleWatch kernel(Sandbox)[0] : SandboxViolation: MyWatchApp(203) deny(1) network-outbound /private/var/run/mDNSResponder

用于调用的代码是使用改装完成的,并且可以在模拟器上运行,所以我认为这不是原因,但如有必要,我会发布.

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 设备因 SandboxViolation deny(1) 网络出站而崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆