3

I am implementing a NEPacketTunnelProvider and loading it from my view controller using:

var vpnManager: NETunnelProviderManager = NETunnelProviderManager()
...
let providerProtocol = NETunnelProviderProtocol()
providerProtocol.providerBundleIdentifier = "AA.BB.CC"
providerProtocol.serverAddress = "<something>"
...
self.vpnManager.localizedDescription = "My app"
self.vpnManager.protocolConfiguration = providerProtocol
self.vpnManager.isEnabled = true
self.vpnManager.connection.startVPNTunnel()

Parts marked with "..." seemed irrelevant.

My understanding (although it's really not clear in the documentation) is that when I do this, and I have a target that was created as type "NetworkExtension" with BundleId AA.BB.CC, that the extension would be loaded and executed properly. So, my understanding is that startTunnel (from NEPacketTunnelProvider) will implicitly be called from the code block above.

I put a NSLog("STARTING TUNNEL!!!!!") right at the top of the startTunnel method, but am not sure where to see that. So far, I have viewed the logs in:

  1. Console
  2. Window > Devices and simulators > View device logs

None of these appear to show the logs from within the extension. The problem is that the extension seems to crash before I can attach to the running process, so I have the feeling I'm just "missing" that log because I can't attach quickly enough.

Short question

How can I attach to a running network extension quickly enough so that I don't miss an NSLog that is run immediately?

wheresmycookie
  • 683
  • 3
  • 16
  • 39

1 Answers1

3

The logs from Network extensions do not go to Xcode console. to see the logs from Network extension you have to follow the bellow steps.

  1. Open the console application.

  2. Select your iOS device running the network extension you will see all the logs from your device.

  3. Filter the logs by Network extension target name now you will see the logs only from your network extension.

How can I attach to a running network extension quickly enough?

What I have been doing to solve this problem was, put the thread on sleep right before log statement.

sleep(60)

It will give you enough time to attach the Network Extension process for debug.

Imran
  • 3,045
  • 2
  • 22
  • 33