Connect to VPN programmatically in iOS 8

后端 未结 2 1109
北恋
北恋 2020-12-04 12:35

Since the release of iOS 8 beta, I found a Network Extension framework in its bundle which is going to let developers configure and connect to VPN servers programmatically a

2条回答
  •  臣服心动
    2020-12-04 13:24

    The problem is the error you are getting when saving: Save error: Error Domain=NEVPNErrorDomain Code=4

    If you look in the NEVPNManager.h header file, you will see that error code 4 is "NEVPNErrorConfigurationStale". The configuration is stale and needs to be loaded. You should call loadFromPreferencesWithCompletionHandler: and in the completion handler modify the values you want to modify, and then call saveToPreferencesWithCompletionHandler:. The example in your question is modifying the configuration before the loading is completed, which is why you are getting this error.

    More like this:

    [manager loadFromPreferencesWithCompletionHandler:^(NSError *error) {
         // do config stuff
         [manager saveToPreferencesWithCompletionHandler:^(NSError *error) {
         }];
    }];
    

提交回复
热议问题