NERelay save to preferences error

I am developing an App based on Network Extension that lets all network requests on device access the Internet through a private Relay.

I created an empty iOS App and only the entitlements file and ViewController.swift(Main.storyboard) file have been modified. The code was copied from the official video https://developer.apple.com/videos/play/wwdc2023/10002/

But, running the App on iPhone, the saveToPreferences API reported Error Domain=NERelayErrorDomain Code=3 "(null)" and the App doesn't look like it's changed at all (it doesn't jump to the Settings - VPN&Relay). Does anyone know why?Any reply would be greatly appreciated.

  • The contents of the entitlements file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.developer.networking.networkextension</key>
	<array>
		<string>relay</string>
	</array>
</dict>
</plist>
  • ViewController.swift:
import UIKit
import NetworkExtension

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    @IBAction func tap(_ sender: Any) {

        let newRelay = NERelay()
        let relayURL = URL(string: "https://relay.example.com:443/")
        newRelay.http3RelayURL = relayURL
        newRelay.http2RelayURL = relayURL

        newRelay.additionalHTTPHeaderFields = ["Authorization" : "PrivateToken=123"]

        let manager = NERelayManager.shared()
        manager.relays = [newRelay]
        manager.matchDomains = ["internal.example.com"]

        manager.isEnabled = false
        manager.saveToPreferences { err in
            print(err)
        }
        
    }
    
}
Answered by DTS Engineer in 829031022

Error 3 in the NERelayErrorDomain is NERelayManagerClientErrorServerUnreachable, with a doc comment of The relay server prematurely disconnected the connection. That suggests that the system reached out to the relay you supply to confirm its setup, and it failed to respond correctly.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Error 3 in the NERelayErrorDomain is NERelayManagerClientErrorServerUnreachable, with a doc comment of The relay server prematurely disconnected the connection. That suggests that the system reached out to the relay you supply to confirm its setup, and it failed to respond correctly.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

NERelay save to preferences error
 
 
Q