When I use NEHotspotConfigurationManager connect to a WiFi in iOS app, it can work fine.
However, I run this app in M1 Mac to connect to a WiFi always get the message:
Domain=NEHotspotConfigurationErrorDomain Code=8 "internal error." UserInfo={NSLocalizedDescription=internal error.}
I choose run destination:
My Mac(Designed for iPhone)
This is code I am use in my project:
NEHotspotConfiguration * hotspotConfig = [[NEHotspotConfiguration alloc] initWithSSID:_wifi_SSID passphrase:_wifi_PASSWORD isWEP:NO];
[[NEHotspotConfigurationManager sharedManager] applyConfiguration:hotspotConfig completionHandler:^(NSError * _Nullable error) {
NSLog(#"=%#", error);
if (!error) {
NSLog(#"Success to connect");
}else{
NSLog(#"Fail to connect or already to connect");
}
}];
I don't understand if NEHotspotConfigurationManager support Mac WiFi setting.
Thanks in advance!
Related
I am trying to do autoconnect in iOS with below code
if([Utils isEmpty:password]){
configuration = [[NEHotspotConfiguration alloc] initWithSSID: wifiSSID];
}else{
configuration = [[NEHotspotConfiguration alloc] initWithSSID: wifiSSID passphrase: password isWEP: NO];
}
configuration.joinOnce = YES;
/* Alert the OS that the user wants to connect to the WiFi */
[[NEHotspotConfigurationManager sharedManager] applyConfiguration: configuration completionHandler: ^ (NSError * _Nullable error) {
if (nil == error) {
DLog (# "Is Connected!!");
[WiFiManager sendCallback:CONNECTED callback:callback];
} else {
DLog (# "Error is:%#", error);
[WiFiManager sendCallback:UNKNOWN callback:callback];
}}];
Here I have joinOnce = YES.
What does this actually do when it is set to NO.
I don't find any real difference between YES and NO.
Anyone please explain.
When joinOnce is set to true, it means that the connection to that hotspot will be disconnected and the configuration will be forgotten as soon as the device sleeps or your application has been in the background for some time.
This happened only in iOS 9.3.5 (not sure about other 9 or below), not occur in iOS 10.x.
When I use AFNetworking to connect to an API URL, it just run into failure callback with error like below:
LOG: Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to
the server." UserInfo={NSErrorFailingURLStringKey=APIURL,
_kCFStreamErrorCodeKey=-2200, NSErrorFailingURLKey=APIURL, NSLocalizedDescription=Could not connect to the server.,
_kCFStreamErrorDomainKey=4, NSUnderlyingError=0x16146990 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)"
UserInfo={_kCFStreamErrorDomainKey=4, NSErrorPeerAddressKey={length =
16, capacity = 16, bytes = 0x100201bb253ce7160000000000000000},
_kCFStreamErrorCodeKey=-2200}}}
When I paste the API to safari browser (same device), it ask me to trust a certificate or something like that, so I'm afraid there's something wrong in the configuration in the app.
My call for URL:
self.sessionManager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseUrl sessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
self.sessionManager.securityPolicy.allowInvalidCertificates = YES;
self.sessionManager.securityPolicy.validatesDomainName = NO;
self.sessionManager.requestSerializer.timeoutInterval = timeout;
self.sessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
// Call API:
[self.sessionManager POST:path parameters:dictParams progress:nil success:^(NSURLSessionTask *task, id responseObject) {
// success block
} failure:^(NSURLSessionTask *task, NSError *error) {
// failure block
}
I've even set NSAllowsArbitraryLoads=true in App Transport Security Settings inside info.plist.
How to fix this? I found this question have the similar error, but I'm not so sure. I don't have access to the API host and in ios 10.x it works just fine. When using postman it works too.
In my app I am trying to configure VPN settings in App load delegate. I am calling following method in my app delegate
- (void)configureVPN {
NEVPNManager *manager = [NEVPNManager sharedManager];
[manager loadFromPreferencesWithCompletionHandler:^(NSError * _Nullable loadError) {
if (loadError) {
NSLog(#"vpn setup error: %#", loadError);
} else {
[manager setOnDemandEnabled: YES];
NSMutableArray *rules = [[NSMutableArray alloc] init];
NEOnDemandRuleConnect *connectRule = [NEOnDemandRuleConnect new];
[rules addObject:connectRule];
[manager setOnDemandRules:rules];
[manager saveToPreferencesWithCompletionHandler:^(NSError * _Nullable saveError) {
if (saveError) {
NSLog(#"vpn setup error: %#", saveError);
} else {
NSLog(#"vpn config set");
NSError *connError;
[manager.connection startVPNTunnelAndReturnError:&connError];
if (connError) {
NSLog(#"Unable to connect to VPN: %#", connError);
} else {
NSLog(#"VPN connection established");
}
}
}];
}
}];
}
but I am getting error on manager loadFromPreferencesWithCompletionHandler
Error:
Failed to load the configuration: Error Domain=NEVPNErrorDomain Code=5 "permission denied" UserInfo={NSLocalizedDescription=permission denied}
I thought it was because of missing capabilities but Personal VPN is enabled in capabilities.
Go to Xcode -> Project -> Targets -> Capabilities and
Enable VPN and Enable Network Extensions.
To fix the issue, go to Xcode > Project > capabilities and enable personal VPN.
In my case, I had added the Capabilities correctly, but an error is still reported
when I restart my iPhone , then run the project, every thing work fine
Sometimes I am getting this error
Error Domain=NSPOSIXErrorDomain Code=65 "No route to host"
UserInfo={NSLocalizedDescription=No route to host,
NSLocalizedFailureReason=Error in send() function.}
when opening udp socket in some routers. I don't know what causes this.
This is my code for opening a udp socket:
- (void)openSocket
{
if(_asyncUdpSocket == nil)
{
_asyncUdpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
}
if(![_asyncUdpSocket isClosed])
{
return;
}
NSError *error;
if (![_asyncUdpSocket enableBroadcast:YES error:&error])
{
NSLog(#"AsyncUdp: enable broadcast failed error: %#", error);
}
if (![_asyncUdpSocket bindToPort:_port error:&error])
{
NSLog(#"AsyncUdp: bind to port %li failed error: %#", (unsigned long)_port, error);
}
if (![_asyncUdpSocket joinMulticastGroup:_address error:&error])
{
NSLog(#"AsyncUdp: join multicast group %# failed error: %#", _address, error);
}
if(![_asyncUdpSocket beginReceiving:&error])
{
NSLog(#"AsynUdp: begin receiving error: %#", error);
}
if(error != nil)
{
NSLog(#"Udp failed to open!");
[_delegate onUdpSocketDidOpenfailed];
}
else
{
NSLog(#"UdpSocket - opend udp socket successful!");
[_delegate onUdpSocketDidOpen];
}
}
Take note that this happens really often in iPhone 7
After updating Xcode to Version 12.5, I got the same issue when run a DLNA App project. I fixed it by downgrading Xcode to Version 12.4.
I am trying to fetch a record with CloudKit and it fails with the following error: "Fetching asset failed" I confirmed (via the CloudKit Dashboard) that the record exists in my public database and the default zone and the default container (not a custom container). Here is my code:
CKContainer *container = [CKContainer defaultContainer];
CKDatabase *publicDatabase = [container publicCloudDatabase];
CKRecordID *artworkRecordID = [[CKRecordID alloc] initWithRecordName:#"1C0DCC08-71D3-4C47-A417-DB92D2EECB67"];
[publicDatabase fetchRecordWithID:artworkRecordID completionHandler:^(CKRecord *artworkRecord, NSError *error) {
if (error) {
// Error handling for failed fetch from public database
}
else {
// Display the fetched record
}
}];
I had a user get this because they weren’t signed in to iCloud in their iPhone Settings.
As you can see in your screenshot the error code is 4 which is a network error
See xcdoc://?url=developer.apple.com/library/ios/documentation/CloudKit/Reference/CloudKit_constants/index.html#//apple_ref/c/tdef/CKErrorCode
Try switching to 3G or WiFi to see if there is different behavior.
If you go to your app settings, is mobile data enabled?
Can you run the code from the simulator?