run packettunnelprovider for local

Hi
I want to use packet tunnel provider for manage traffic usage on ios device, and I do not want to connect to a remote vpn server ( I mean the address target is 127.0.0.1 or localhost). I want to use it for adblocking purpose on all traffic data in all applications
So here is my question, how can I config the tunnel provider protocol for run in localhost:
here is my configuration:
Code Block  
let providerProtocol = NETunnelProviderProtocol()
providerProtocol.providerBundleIdentifier = "com.project.tunnel"
providerProtocol.serverAddress = "127.0.0.1"
//???? providerProtocol.username = "uid"
vpnManager.localizedDescription = "local"
vpnManager.protocolConfiguration = providerProtocol
vpnManager.isEnabled = true
self.vpnManager.saveToPreferences { (err) in
self.loadConfig()
}


and the loadConfig() function is:
Code Block
func loadConfig() {
        vpnManager.loadFromPreferences { (err) in
            if let err = err {
                print(">>error is :\(err.localizedDescription)")
            }
            
            do {
                try self.vpnManager.connection.startVPNTunnel()
            } catch {
                print(">> error when connect is \(error.localizedDescription)")
            }
        }
    }


and also I used { NEVPNManager.shared() }() for defining vpnManager

Replies

I want to use it for adblocking purpose on all traffic data in all applications

Filtering traffic for adblocking purposes is by default a content filter action and should be handled by a content filter provider such as NEFilterDataProvider and not a NEPacketTunnelProvider. Having said that, content filters on iOS are for only managed devices and cannot be deployed to the App Store.

In the context of a Packet Tunnel, there is nothing technically stopping you from doing this, but it would be considered a non-supported use case for a Packet Tunnel. Which means you’ll run into various obscure edge cases that may not have good solutions, and such solutions that you do find are likely to be very brittle.


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com

Filtering traffic for adblocking purposes is by default a content filter action and should be handled by a content filter provider such as NEFilterDataProvider and not a NEPacketTunnelProvider. Having said that, content filters on iOS are for only managed devices and cannot be deployed to the App Store. 

first thanks for the reply Matt, the problem that I have is I must block some traffic content by code without connecting to any remote servers, I want to use NEFilterDataProvider but the problem is it needs a NEPacketTunnelProvider and I must run it before.

I need to filter contents entire the device ( includes all apps on the cell phone such as instagram, telegram, chrome, safari and etc) so I cannot use safari extension.

So the main question: is that anyway to filter traffic content entire an iOS device without an external server??