NEVPNManager saveToPreferencesWithCompletionHandler cause app restart

Does anybody faced with such problem?

When code run saveToPreferencesWithCompletionHandler app restarts by itself without crash, no errors in console.

NEVPNManager *manager = [NEVPNManager sharedManager];

    [manager loadFromPreferencesWithCompletionHandler:^(NSError * _Nullable error) {

        if (error) {
#if DEBUG
              NSLog(@"loadFromPreferencesWithCompletionHandler_error: %@", error.localizedDescription);
#endif
            return;
        }

        NSString *serverURL = [self vpnServerURLWithCountryItem:countryItem];
        NSData *passwordReference = [self persistentReferenceForSavedPassword:credentials.password
                            service:@"passwordReferenceIKeV2"
                            account:credentials.username];

        [KeychainManager save:@"passwordReferenceIKeV2" data:passwordReference];

        NEVPNProtocolIKEv2 *protocol = [[NEVPNProtocolIKEv2 alloc] init];
        protocol.username = credentials.username;
        protocol.passwordReference = passwordReference;
        protocol.serverAddress = serverURL;
        protocol.serverCertificateIssuerCommonName = @"letsencrypt";
        protocol.authenticationMethod = NEVPNIKEAuthenticationMethodNone;
        protocol.disconnectOnSleep = NO;
        protocol.useExtendedAuthentication = YES;
        protocol.IKESecurityAssociationParameters.encryptionAlgorithm = NEVPNIKEv2EncryptionAlgorithmAES256;
        protocol.IKESecurityAssociationParameters.integrityAlgorithm = NEVPNIKEv2IntegrityAlgorithmSHA256;
        protocol.IKESecurityAssociationParameters.diffieHellmanGroup = NEVPNIKEv2DiffieHellmanGroup14;
        protocol.IKESecurityAssociationParameters.lifetimeMinutes = 1440;
        
        protocol.childSecurityAssociationParameters.encryptionAlgorithm = NEVPNIKEv2EncryptionAlgorithmAES256;
        protocol.childSecurityAssociationParameters.integrityAlgorithm = NEVPNIKEv2IntegrityAlgorithmSHA256;
        protocol.childSecurityAssociationParameters.diffieHellmanGroup = NEVPNIKEv2DiffieHellmanGroup14;
        protocol.childSecurityAssociationParameters.lifetimeMinutes = 1440;

        protocol.remoteIdentifier = serverURL;
        
        [manager setProtocolConfiguration:protocol];
        [manager setLocalizedDescription:@"Tunnel Name"];
        manager.enabled = YES;
        
        [manager saveToPreferencesWithCompletionHandler:^(NSError * _Nullable saveError) {
            if (saveError) {
#if DEBUG
                NSLog(@"saveToPreferencesWithCompletionHandler: %@", saveError.localizedDescription);
#endif
                return;
            }
            
            if (completionHandler) {
                completionHandler(error);
            }
        }];
    }];

I’d like to clarify what you mean by “app restart”:

  • What platform is this on?

  • Does the app actually restart? Or do you mean that you just fall out to the Home screen / Finder?

  • If you run the app in Xcode’s debugger, what does it show when this happens?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Platform: iOS 15.5

It shows an "Add new VPN" prompt and if I cancel I get an error in the block, but when I try to accept it the app restarts The code runs on the main queue so the app is supposed to be locked but the app runs from scratch and I see a launch screen.

So I lost debug mode with no additional messages. Last message i've got:

2022-09-02 10:50:38.452456+0300 Onion Buddy[24711:8306741] [connection] nw_resolver_start_query_timer_block_invoke [C7.1] Query fired: did not receive all answers in time for app-measurement.com:443

Normally when an app disappears out from underneath Xcode, the debugger traps and highlights the cause. However, there are some situations where that doesn’t happen, for example, if the app calls exit. However, even in that case the Xcode console (View > Debug Areas > Activate Console) will show something like:

Program ended with exit code: 1

Do you see that?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I don't.

I've added All Exceptions, All Runtime issues, Swift error breakpoints, but no one fired up.

I have some warnings but if I cancel the prompt the app will work well.

You run your app from the Home screen and reproduce the problem, does that generate a crash report?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

NEVPNManager saveToPreferencesWithCompletionHandler cause app restart
 
 
Q