我收到错误:
Error Domain=NEVPNErrorDomain Code=5 "permission denied"
当我尝试在NETunnelProviderManager上保存配置时。这是我的代码:
NETunnelProviderManager * man = [[NETunnelProviderManager alloc] init];
NETunnelProviderProtocol *protocol = [[NETunnelProviderProtocol alloc] init];
[protocol setServerAddress:@"aaa.bbb.ccc.ddd"]; // not actual value
[protocol setUsername:@"testuser"];
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
NSData *data = [[NSData alloc] init];
[dictionary setObject:@"UUID" forKey:(id)kSecAttrService];
[dictionary setObject:data forKey:(id)kSecValueData];
[dictionary setObject:(__bridge id)kSecAttrAccessibleAlways forKey:(id)kSecAttrAccessible];
[dictionary setObject:(__bridge id)kSecClassGenericPassword forKey:(id)kSecClass];
[dictionary setObject:(__bridge id)kCFBooleanTrue forKey:(id)kSecReturnPersistentRef];
CFTypeRef passwordRef = nil;
OSStatus delStatus = SecItemDelete((__bridge CFDictionaryRef)dictionary);
OSStatus status = SecItemAdd((__bridge CFDictionaryRef)dictionary, &passwordRef);
[protocol setPasswordReference:(__bridge NSData * _Nullable)(passwordRef)];
man.protocolConfiguration = protocol;
man.localizedDescription = @"My VPN";
man.onDemandEnabled = NO;
man.enabled = YES;
[man saveToPreferencesWithCompletionHandler:^(NSError *err) {
NSLog(@"saved preferences: error = %@", err);
}];
我在功能中启用了个人VPN,并在应用和网络扩展中都有.entitlements文件。