I have the problem with NETunnelProviderManager and PacketTunnelProvider.
When I try to make a connection (by OpenVPN), there is an instant disconnect.
I am using OpenVPNAdapter.framework for this.
I put nslog in all methods in PacketTunnelProvider and none were printed....
I have the following logs in the console:
Code Block objective-c NEVPNStatusInvalid Save successfully Connection established! NEVPNStatusConnecting NEVPNStatusDisconnected
I checked all the .entitlements and other parameters.
As I think they are okay.
However, if you could check them again, I would be grateful.
Below I am pasting links to images.
My code:[Main target settings](https://ibb.co/zmHRP2z)
[Extension target settings](https://ibb.co/tQdNNNY)
[Main target .entitlements](https://ibb.co/SwwY8L8)
[Extension target .entitlements](https://ibb.co/kJg7q6W)
[Extensions Info.plist](https://ibb.co/th2xSzm)
Code Block objective-c - (IBAction) buttonAction:(id)sender { [self connection]; }
Code Block objective-c - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onVpnStateChange:) name:NEVPNStatusDidChangeNotification object:nil]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:@"...."]]; [request setHTTPMethod:@"GET"]; NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; [[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSString* requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; NSData* responseData = [requestReply dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error]; weak.configData = [jsonDict[@"config"] dataUsingEncoding:NSUTF8StringEncoding] [weak initProvider]; }] resume]; }
Code Block objective-c -(void)initProvider { __weak typeof(self) weak = self; [NETunnelProviderManager loadAllFromPreferencesWithCompletionHandler:^(NSArray<NETunnelProviderManager*>* _Nullable managers, NSError* _Nullable error) { if(error){ NSLog(@"error: %@",error); return; } weak.providerManager = managers.firstObject ? managers.firstObject : [NETunnelProviderManager new]; [weak.providerManager loadFromPreferencesWithCompletionHandler:^(NSError * _Nullable error) { if(error){ NSLog(@"initProvider [weak.providerManager loadFromPreferencesWithCompletionHandler] error: %@",error); return; } NETunnelProviderProtocol *tunel = [[NETunnelProviderProtocol alloc] init]; tunel.providerBundleIdentifier = @"....com.MyVPN.PacketTunnel"; tunel.providerConfiguration = @{ @"ovpn" : self.configData }; tunel.serverAddress = @"vpn.superVPN.com"; tunel.disconnectOnSleep = NO; weak.providerManager.protocolConfiguration = tunel; weak.providerManager.localizedDescription = @"superVPN"; [weak.providerManager setEnabled:YES]; [weak.providerManager saveToPreferencesWithCompletionHandler:^(NSError *error) { if(error) { NSLog(@"Save error: %@", error); }else { NSLog(@"Save successfully"); } }]; }]; }]; }
Code Block objective-c - (void)connection { __weak typeof(self) weak = self; [self.providerManager loadFromPreferencesWithCompletionHandler:^(NSError * _Nullable error) { if(!error){ NSError *error = nil; [weak.providerManager.connection startVPNTunnelAndReturnError:&error]; if(error) { NSLog(@"Start error: %@", error.localizedDescription); }else{ NSLog(@"Connection established!"); } }else{ NSLog(@"connection error:%@",error); } }]; }
I just don't know what the problem might be. Maybe in PacketTunnelProvider ?
The code for PacketTunnelProvider was taken from here.
All tests I run on a real device (iPhone iOS 12.4.4)
Xcode Version 12.4 (12D4e)
My .ovpn file is correct because it good works on android version of application.
Please help me, I don't know where to look for the answer.
There are similar questions on stackoverflow, but no one answered them.