Posts

Post marked as solved
6 Replies
1.9k Views
Hi, I am currently building my own VPN application using NetworkExtension's PacketTunnelProvider. I want to send information from the PacketTunnelProvider to the ViewController when a VPN connection fails and to tell the user why. The code now is as shown below. When the startTunnel() being overwritten is executed, somehow NotificationCenter.default.post(name: NSNotification.Name.NEVPNStatusDidChange, object: nil) is executed and VPNStatusDidChange(_ notification: Notification?) in the ViewController is called and displays some message. I tried to do the same thing by writing NotificationCenter.default.post(name: NSNotification.Name(rawValue: "testnotify"), object: nil) in the PacketTunnelProvider.swift , but it does not work. What is wrong? Here is a part of current PacketTunnelProvider.swift override func startTunnel(options: [String : NSObject]? = nil, completionHandler: @escaping (Error?) -> Void) {   conf = (self.protocolConfiguration as! NETunnelProviderProtocol).providerConfiguration! as [String : AnyObject]   self.setupWSSession()       DispatchQueue.global().async {     while (self.connectionPhase < 5) {       Thread.sleep(forTimeInterval: 0.5)     }     self.tunToWS()   } NotificationCenter.default.post(name: NSNotification.Name(rawValue: "testnotify"), object: nil) } And here is a part of ViewController.swift override func viewDidLoad() {     super.viewDidLoad()     initVPNTunnelProviderManager()     NotificationCenter.default.addObserver(self, selector: #selector(ViewController.VPNStatusDidChange(_:)), name: NSNotification.Name.NEVPNStatusDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(ViewController.receieve(_:)), name: NSNotification.Name(rawValue: "testnotify"), object: nil)     } @objc func VPNStatusDidChange(_ notification: Notification?) {   print("VPN Status changed:")   let status = self.vpnManager.connection.status   switch status {   case .connecting:     print("Connecting...")     connectButton.setTitle("Disconnect", for: .normal)     break   case .connected:     print("Connected...")     connectButton.setTitle("Disconnect", for: .normal)     break   case .disconnecting:     print("Disconnecting...")     break   case .disconnected:     print("Disconnected...")     connectButton.setTitle("Connect", for: .normal)     break   case .invalid:     print("Invliad")     break   case .reasserting:     print("Reasserting...")     break   } } @objc func receive(_ notification: Notification?) {     print("receive Notification!") }
Posted Last updated
.
Post marked as solved
1 Replies
980 Views
Hello. I am currently creating a VPN app using Network Extension and am encountering an issue that seems like a memory leak. The name of the NetworkExtention that makes the VPN connection is NEPacketTunnelVPNDemo, and this Extension works by being called by an application named udpVPN. To enable Malloc Stack logging, the scheme needs to be edited, so I changed the scheme of "NEPacketTunnelVPNDemo" like this. The program terminated due to lack of memory and when I displayed the memory graph, it looked like this. When I try to select one of them and check the backtrace, it shows like the image, and I cannot check the backtrace. How can I make it possible to check the backtrace? Best,
Posted Last updated
.
Post not yet marked as solved
0 Replies
317 Views
Hi. I am developing an App with Network Extension, and when I use git stash or checkout, the Build scheme for App disappears and only the Build scheme for Extension remains. When I restart Xcode, the Build Scheme for App appears, but it is hard to restart it every time. So, please tell me how to solve this problem. Now I'm using Xcode Version 14.0.1 (14A400) on macOS12.6.
Posted Last updated
.
Post marked as solved
2 Replies
1.2k Views
Hi. I am currently implementing inter-application communication using DistributedNotificationCenter within swift 5.6 and Xcode Version 13.3.1 (13E500a). So I typed the code below into Playground, but I get the error "Cannot find 'DistributedNotificationCenter' in scope". import Foundation let dnc = DistributedNotificationCenter.default() As this document says, DistributedNotificationCenter is included in the Fundation, so I should be able to use it if I write it that way, but I can't. I would appreciate it if you could tell me how I can use DistributedNotificationCenter Thanks,
Posted Last updated
.