NEHotspotConfigurationErrorDomain Code=5 "invalid EAP settings." - ios

I'm using NEHotspotConfigurationManager with on iOS 11 iPhone to connect to specific Wi-Fi spot and then disconnect from it.
Here is the code:
let domainName = ""
let hotspotSettings = NEHotspotHS20Settings.init(domainName: domainName, roamingEnabled: true)
let hotspotEAPSettings = NEHotspotEAPSettings()
hotspotEAPSettings.username = *****
hotspotEAPSettings.password = ******
hotspotEAPSettings.isTLSClientCertificateRequired = true
hotspotEAPSettings.supportedEAPTypes = [21]
hotspotEAPSettings.trustedServerNames = [""]
hotspotEAPSettings.ttlsInnerAuthenticationType = .eapttlsInnerAuthenticationMSCHAPv2
print(hotspotEAPSettings)
let hotspotConfig = NEHotspotConfiguration.init(hs20Settings: hotspotSettings, eapSettings: hotspotEAPSettings)
print( hotspotConfig.ssid)
NEHotspotConfigurationManager.shared.apply(hotspotConfig) {[unowned self] (error) in
print(error?.localizedDescription as Any)// gives Error Domain=NEHotspotConfigurationErrorDomain Code=5 "invalid EAP settings."
print(error as Any)
if let error = error {
self.showError(error: error)
} else {
self.showSuccess()
}
}
Question is: what happened? Why it prompts me error "invalid EAP settings", and also what does this error mean?

For this first we had to save certificate which comes in .mobileconfig file into iPhone keychain in $TeamID.com.apple.networkextensionsharing group, also enable the keychain access group in xCode capability and add $TeamID.com.apple.networkextensionsharing into entitlements.After successfully save the certificate into keychain it works.

Related

Xcode HomeKit add device to Home app using X-HM: or code pin

I learn the Homekit to integrate my IOT device.
let payload = HMAccessorySetupPayload.init(url: URL.init(string: "X-HM://XXXXXXXXX"))
let request = HMAccessorySetupRequest()
request.payload = payload
let setupManager = HMAccessorySetupManager()
setupManager.performAccessorySetup(using: request) { (result, error) in
if (error != nil) {
print("Error from addAndSetupAccessories:", [error?.localizedDescription])
} else {
print("The accessory is added.")
}
}
The "X-HM" link is provided by OpenHab but it returned a error:
Failed to perform accessory setup using request: Error Domain=HMErrorDomain Code=17 "(null)"
I find other user say you need set the permission but I cannot set this in Entitlements file. It return error not find this.
“com.apple.developer.homekit.allow-setup-payload”
Question 1:
in the Homekit doc mean, the link must join "MFi Program"?
====
Question 2:
also, i have the pin code, Could i skip the input step in app setup?
i use the below code but this has not option to input the pin code, it need user to input using keyboard.
let setupManager = HMAccessorySetupManager()
setupManager.performAccessorySetup(using: HMAccessorySetupRequest()) { (result, error) in
if (error != nil) {
print("Error from addAndSetupAccessories:", [error?.localizedDescription])
} else {
print("The accessory is added.")
}
}

iOS - TunnelKit OpenVPNTunnelProvider ProviderConfigurationError

I am trying to create an ios vpn client using Tunnelkit. I am following this tutorial.
https://github.com/passepartoutvpn/tunnelkit
am able to compile and run the application, but when I try to connect, the app crashes and throwing.
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error:
TunnelKit.OpenVPNTunnelProvider.ProviderConfigurationError.credentials(details:
"keychain.set()")
Anyone who had already set up tunnel kit OpenVPN, please help to resolve this issue.
func connect() {
let server = textServer.text!
let domain = textDomain.text!
let hostname = ((domain == "") ? server : [server, domain].joined(separator: "."))
let port = UInt16(textPort.text!)!
let socketType: SocketType = switchTCP.isOn ? .tcp : .udp
let credentials = OpenVPN.Credentials(textUsername.text!, textPassword.text!)
let cfg = Configuration.make(hostname: hostname, port: port, socketType: socketType)
let proto = try! cfg.generatedTunnelProtocol(
withBundleIdentifier: tunnelIdentifier,
appGroup: appGroup,
credentials: credentials
)
let neCfg = NetworkExtensionVPNConfiguration(title: "new title", protocolConfiguration: proto, onDemandRules: [])
vpn.reconnect(configuration: neCfg) { (error) in
if let error = error {
print("configure error: \(error)")
return
}
}
}
You need to follow the integration steps.
https://github.com/passepartoutvpn/tunnelkit#demo
Enable App Groups and Keychain Sharing capabilities
make sure the appGroup value is the same which you set in your target/Signings & Capabilities/App Groups

Swift - unable to connect to open hotspot

I'm attempting to connect to an open Wi-Fi network using the NEHotspotConfigurationManager without any luck. I've ensured my app has the proper Hotspot Configuration Entitlement and I'm running on a device that is > iOS 11.
Here is the code I'm using to connect to the open network.
// MARK: - Connect to Hotspot
#available(iOS 11.0, *)
func connectToHotspot(completion: #escaping APConnectionStatusHandler) {
let configuration = NEHotspotConfiguration.init(ssid: Constants.hotspotSSID)
configuration.joinOnce = true
NEHotspotConfigurationManager.shared.apply(NEHotspotConfiguration.init()) { connectionError in
if let error = connectionError {
debugPrint("Failed to automatically connect to \(Constants.hotspotSSID)")
debugPrint(error)
completion(false, error.localizedDescription)
}
else {
debugPrint("Automatically connected to \(Constants.hotspotSSID)")
completion(true, nil)
}
}
}
connectionError is populated every time I run this with:
Domain=NEHotspotConfigurationErrorDomain Code=1 "invalid SSID."
I'm unable to find any information on what exactly this error message means. The network shows up in the list of networks for the device I'm using. I'm spelling it correctly and the error message is the same regardless of what SSID string I use.
Any recommendations?
Maybe you shouldn't use Constant.hotspotSSID.
According to the afore-mentioned, I cannot identify what is the 'Constant' or which data type it is.
Here is my thought, try this:
let yourSSID: String = "SSID"
let configuration = NEHotspotConfiguration.init(ssid: yourSSID)
configuration.joinOnce = true
NEHotspotConfigurationManager.shared.apply(configuration) {
(error) in
if error != nil {
print("Connect-> Failure!")
} else {
print("Connect-> Success!")
}
}

Getting errors from Twitter.sharedInstance() Swift 3 iOS 10

I am writing app with Swift 3 on iOS 10. sharedInstance() method throws errors to console when user deny permissions to account from systems or account is not configured (e.g. "Unable to authenticate using the system account"). Errors are shows on console before enter to closure. I wont shows this errors to users in app e.g. on alert. This is my code:
Twitter.sharedInstance().logIn { (session, error) in
if error != nil {
// print(error?.localizedDescription ?? " ")
return
})
I get this error:
2016-11-29 14:49:09.023 CarReview[1254:31719] [TwitterKit] did encounter error with message "Unable to authenticate using the system account.": Error Domain=TWTRLogInErrorDomain Code=2 "User allowed permission to system accounts but there were none set up." UserInfo={NSLocalizedDescription=User allowed permission to system accounts but there were none set up.}
2016-11-29 14:49:09.024 CarReview[1254:31719] [TwitterKit] No matching scheme found.
2016-11-29 14:49:09.292 CarReview[1254:31719] [TwitterKit] did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "<?xml version="1.0" encoding="UTF-8"?>
<hash>
<error>Desktop applications only support the oauth_callback value 'oob'</error>
<request>/oauth/request_token</request>
</hash>
" UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?>
<hash>
<error>Desktop applications only support the oauth_callback value 'oob'</error>
<request>/oauth/request_token</request>
</hash>
}
I want show users this: "Unable to authenticate using the system account. User allowed permission to system accounts but there were none set up."
I am facing the same issue as in the question.
I have just set the callBack Url into the Twitter App and resolved the issues.
Go to https://apps.twitter.com/app -> Settings -> Callback URL and Update Settings to save.
I'm not sure I understand what you want to do but you probably want to print the result on the main thread:
Twitter.sharedInstance().logIn{(session, error) in
DispatchQueue.main.async{
if error != nil {
print("Failed to login with Twitter / error:", error!.localizedDescription)
}else{
print("succeeded")
}
}
}
OK, I use this code to notify user about some error:
if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter) {
if ACAccountStore().accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter).accessGranted {
Twitter.sharedInstance().logIn{
(session, error) in
if error != nil {
self.showAlert(title: "Twitter - Error", message: (error?.localizedDescription)!)
return
}
guard let token = session?.authToken else { return }
guard let secret = session?.authTokenSecret else { return }
let credential = FIRTwitterAuthProvider.credential(withToken: token, secret: secret)
FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in
if error != nil {
self.showAlert(title: "Firebase (Twitter)", message: (error?.localizedDescription)!)
return
}
self.showAlert(title: "Firebase (Twitter)", message: "Logged to Firebase via Twitter.")
})
}
} else {
showAlert(title: "Twitter - Error", message: "Give access to the system Twitter account.")
}
} else {
showAlert(title: "Twitter - Error", message: "No system accounts set up.")
}
But it isn't what I want:/
You need to use withMethods and specify using the systemAccounts, not webBased or all to use the iOS Twitter settings. The following code is in Swift 3:
twitSharedInstance.logIn(withMethods: .systemAccounts) { (session :TWTRSession?, error :Error?) in
if (error != nil) {
if (session != nil) {
//We have logged into Twitter.
}
}
}

Error when I'm using MailCore2 in Swift 2

I'm using the MailCore2 at Swift in my iOS application to send message to email in the background without open built-in mail application, But when I'm running app on my device ( real device ) I have this problem:
My complete code for send button:
#IBAction func sendButton(sender: AnyObject) {
var smtpSession = MCOSMTPSession()
smtpSession.hostname = "smtp.gmail.com"
smtpSession.username = "from-email"
smtpSession.password = "password"
smtpSession.port = 465
smtpSession.authType = MCOAuthType.SASLPlain
smtpSession.connectionType = MCOConnectionType.TLS
smtpSession.connectionLogger = {(connectionID, type, data) in
if data != nil {
if let string = NSString(data: data, encoding: NSUTF8StringEncoding){
NSLog("Connectionlogger: \(string)")
}
}
}
var builder = MCOMessageBuilder()
builder.header.to = [MCOAddress(displayName: "AAA", mailbox: "to-email")]
builder.header.from = MCOAddress(displayName: "RRR", mailbox: "from-email")
builder.header.subject = messageTitleTextField.text
var message = messageTextView.text
builder.htmlBody = message
let rfc822Data = builder.data()
let sendOperation = smtpSession.sendOperationWithData(rfc822Data)
sendOperation.start { (error) -> Void in
if (error != nil) {
NSLog("Error sending email: \(error)")
} else {
NSLog("Sent successfully, Thanks!")
}
}
}
Error:
Optional(Error Domain=MCOErrorDomain Code=5 "Unable to authenticate with the current session's credentials." UserInfo={NSLocalizedDescription=Unable to authenticate with the current session's credentials.})
Already I change setting of unsecure app from gmail account but I solved the credentials problem by unlocking gmail account from this link
https://accounts.google.com/DisplayUnlockCaptcha
In my case I had to "Change account access for less secure apps"
https://support.google.com/accounts/answer/6010255?hl=en
If somebody has this problem its quite helpful to know that it is actually problem with security on google side and there it has to be handled...I will leave it because when this happened to me the error didn't say anything I had to search for problem to find out that you have to go to that link on google and find out how to setup it correctly, I wasted time , it will be helpful for others who wants to send mail by smtp with google account

Resources