Network Extension debugging

I'm trying to create a sample NEFilterDataProvider extension based on the new iOS9 API's. I succesfully added a new target using the skeleton that's provided. My issue is - I can't get breakpoints to trigger (I have them scattered all throughout the skeleton code file), and I can't get any device log information from the print statements I'm using in my code for debugging.


I've tried:

  • Running the host app, then attaching to the PID/Name of the extension
  • Running the extension scheme directly against the host app, then trying to attach to the PID/Name


I also have this problem against the sample code. I'm wondering if maybe I'm approaching this the wrong way. I was under the assumption that I can run the host app and the extension gets installed and will run forever in the background. Is there anything I need to do code-wise in the host app to 'activate' the extension to start it? If so, does the extension run in the background continuously after I do so, even when the host app is closed?


Thanks

Replies

Yes, I'm having the same issues. See also my thread here:


https://forums.developer.apple.com/thread/9775


You say print statements, so its worth making sure that you're using NSLog() rather than print(), but in my case I'm using NSLog() and I'm not seeing those in the device log, either.


As for your later question, though, about whether your app needs to 'activate' the extension, yes. I would follow closely what the Content Filter "Enabled" toggle does in the SimpleTunnel sample code. But like your case, I've added NSLog statements throughout the SimpleTunnel providers, and I don't see the output from those in the device log.

  • Hi @bprodoehl How were you able to get SimpleTunnel working with VPN connecting successfully? I am unable to connect to VPN.

Add a Comment

Yeah, NSLog and breakpoints aren't working for me at all, which makes it very difficult to test applications.


Also, I was under the assumption that these extensions would run in the background forever after the host application has been opened initially (even after it's been closed). Is this the case or does the host application have to be open for the extensions to run? I'd like to make an example where I can just block all web pages via the extension and play with it from there, but nothing seems to work thus far (I added the code to activate it via the toggle code in the sample).

Try the latest round of betas. NSLog works for me now. Haven't tried breakpoints yet.

Arg, neither NSLog nor breakpoints are working for me. I'm doing the following in my extension target with breakpoints scattered throughout to no avail. 😟


import NetworkExtension
class FilterDataProvider: NEFilterDataProvider {
  override func startFilterWithCompletionHandler(completionHandler: (NSError?) -> Void) {
       completionHandler(nil)
        NSLog("LMAO%@", 1)
  }
  override func stopFilterWithReason(reason: NEProviderStopReason, completionHandler: () -> Void) {
        NSLog("LMAO %d", 1)
       completionHandler()
  }
  override func handleNewFlow(flow: NEFilterFlow) -> NEFilterNewFlowVerdict {
        NSLog("LMAO %d", 1)
        return .dropVerdict()
  }
}

Does NEFilterDataProvider and related works under non supervised device? Can someone confirm? Can anyone make the sample NEFilter* to work? I setup a dummy rule server and the only indication that something might be going on is that at one point I couldn't browse anymore then I fixed my rules and I can browse again but nothing is blocked. In any event I none of my breakpoints are triggered. Also the said configuration doesn't show anywhere in the system menu so I am not sure what they look like or if it was successfully installed but I do see the prompt asking for permission.

I finally figured some things out. I don't know if that's your problem but I have xode 7 beta3 and beta4 installed side by side. So after this post I removed both and installed the latest again but first try this.


ServerAddress should be <address>:<port>. Now I can connect.


Now for the debugger or log to work you can't do it directly from the main app. So what you need to do is this:


1) start normal debug session on main app (no need to change scheme)

2) one online post said to stop the app in your device (so I closed my app, not sure if this is optional)

3) In xcode do : "Debug | Attach to process by PID or Name". Use "PacketTunnel" (I just went look at the output file and figure that's something to try)

4) start your app in the device again if you did step #2


After that I got a breakpoint in startTunnelWithOptions (the OMG moment).

I am trying to make the Simple tunnel sample to work in my ios9 beta 4 device. No success till now, here are the steps I followed.


1. Xcode 7 beta 3 installed in yosomite.

2. ran server tunnel with port 8779, got this in console

Starting network service on port 8779

Network service published successfully

3. Installed Simpletunnel app in to ios 9 beta 4 device.

4. Tried to to create a packet tunnel configuration with minium options, server address only, the configuration is not getting saved. No error in console or app either.

5. Tried breakpoints in startTunnelWithOptions, the break points never hit!


Please correct me if I am doing any thing wrong, or missing some thing.


Thanks,

Birajendu

I just did another test. There is a simpler way of debugging this.


1) In xcode do : "Debug | Attach to process by PID or Name". Type: "PacketTunnel"

2) start your app in the device again (your breakpoint for your custom tunnel should trigger now).


You can't debug these new target projects from the main project it seems. There is another way mentioned in apple's doc for app extension but it doesn't work for me (i.e.: select scheme you want to debug, PacketTunnel, launch debugging session, it will ask for target app to launch, select SimpleTunnel; but this method doesn't trigger any breakpoints).

Correction. If you have changed code you need to build and start the main program in your device first so all the new binaries are copied over. After that you can do the simple version mentioned above.

Did you ever figure this out? I'm also unable to get the Control or Data Provider to start at all, no matter what.


EDIT: Never mind, figured it out.

Hi,

I'm debugging the SimpleTunnel code.I succesfully ran the server_tunnel and got response like this:


tunnel_server[653:23750] Starting network service on port 553

tunnel_server[653:23750] Network service published successfully

But when i added a simple configuration in PacketTunnel(<ServerAddress>:<553>),the status is connecting always.I tried to telnet the ip(the ip in config.plist),but failed.
Please give me some pieces of advice.


I installed Simpletunnel app in to ios 9.1 ipad2,OS X EI Capitan10.11.3 ,xcode7.2

I tried to telnet the ip(the ip in config.plist),but failed.

If telnet is unable to connect to your server then it’s clear that there’s a problem on the server side of things. Use

lsof
to confirm that your server is actually listening on the port you think it’s listening on. If so, and telnet still doesn’t work, it’s likely that there’s some sort of routing problem is play here, or perhaps a firewall that’s deliberately blocking incoming connections.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Don't telnet the ip in config.plist .


I think the ip in config.plist is interior ip when you connected VPN.


So try to telnet the Server IP (For example: "tunnel_server run in my Mac ,so Server IP is my machine ip ( ifconfig ->"inet 192.168.1.1" )"),and Server Port is you input:


telnet 192.168.1.1 4144

Thank you! This help me activate the breakpoints. But here comes another problem.

When i launch the PacketTunnel part in the app, it jumps to a breakpoint i didn't set and get stuck on it.


It prompts: "Thread 2: EXC_BREAKPOINT (code=1, subcode=0x100107690)" on file ClientTunnel.swift upon line 150

"connection?.write(messageData, completionHandler: completionHandler as! (Error?) -> Void)"


Even if i kept hitting the continue it cannot move away from the line.

Have no idea what's going on.


Xcode8.1 Swift3.0 macOS Sierra

How did you manage to do it ? I have the entitlements as well as I have Log statements . But it doesn't seem like they are being triggered. I am working with Data Provider.