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!")
}
}
Related
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.")
}
}
I am developing app with video calling functionality and I am using Twilio Video for that.
Currently using TwilioVideo SDK v4.6.2 and iOS Version 14.x and Above
I am not able to connect to the TwilioVideo room
Below is my code:
func connect() {
guard let accessToken = self.accessToken, let roomName = self.roomName else {
return
}
prepareAudio()
prepareCamera()
let connectOptions = ConnectOptions(token: accessToken) { (builder) in
builder.isDominantSpeakerEnabled = true
builder.isNetworkQualityEnabled = true
if let localAudioTrack = self.localAudioTrack {
builder.audioTracks = [localAudioTrack]
}
if let localVideoTrack = self.localVideoTrack {
builder.videoTracks = [localVideoTrack]
}
if let preferredAudioCodec = TwiloVideoSettingsManager.shared.audioCodec {
builder.preferredAudioCodecs = [preferredAudioCodec]
}
if let preferredVideoCodec = TwiloVideoSettingsManager.shared.videoCodec {
builder.preferredVideoCodecs = [preferredVideoCodec]
}
if let encodingParameters = TwiloVideoSettingsManager.shared.getEncodingParameters() {
builder.encodingParameters = encodingParameters
}
builder.region = "gll"
builder.roomName = roomName
}
self.room = TwilioVideoSDK.connect(options: connectOptions, delegate: self)
UIApplication.shared.isIdleTimerDisabled = true
}
Response in not received from Twilio in either of the methods mentioned below
func didConnect(to room: Room) {
NSLog("Room: \(room.name) SID: \(room.sid)")
if (room.remoteParticipants.count > 0) {
self.remoteParticipant = room.remoteParticipants[0]
self.remoteParticipant.delegate = self
}
self.delegate.videoServiceManagerDidConnectToRoom(name:room.name)
}
func roomDidFailToConnect(room: Room, error: Error) {
NSLog("Failed to connect to a Room: \(error).")
self.delegate.videoServiceManagerFailToConnectRoom(error: error.localizedDescription)
self.leaveRoom()
}
I am not able connect to the room every time and sometimes I get the error mentioned below :
Failed to connect to a Room: Error Domain=com.twilio.video Code=53000 "Signaling connection error" UserInfo={NSLocalizedDescription=Signaling connection error, NSLocalizedFailureReason=SIP error 408}.
When I check the Twilio logs in debug mode I am not getting any error.
Please guide me to rectify if there is any mistake in my code
Twilio employee here. Error 53000 is somewhat vague and could occur due to different things: https://www.twilio.com/docs/api/errors/53000
I'd suggest the following next steps:
try reproducing this error using the iOS Quickstart app (https://github.com/twilio/video-quickstart-ios)
try running our Networktest on the problematic device: https://www.networktest.twilio.com
There is a real lack of documentation and information in general out there regarding the public container of CloudKit. I'm having an issue where data cannot be sent while a device is on its cellular network, but works perfectly fine when connected to Wifi.
let publicCloudDatabase = CKContainer.default().publicCloudDatabase
let operation = CKModifyRecordsOperation(recordsToSave: [exampleRecord], recordIDsToDelete: nil)
let operationConfiguration = CKOperation.Configuration()
operationConfiguration.allowsCellularAccess = true
operationConfiguration.qualityOfService = .userInitiated
operation.configuration = operationConfiguration
operation.perRecordProgressBlock = {(record, progress) in
print(progress)
}
operation.perRecordCompletionBlock = {(record, error) in
print("Upload complete")
}
publicCloudDatabase.add(operation)
publicCloudDatabase.save(exampleRecord) { [unowned self] record, error in
if let error = error {
print("public cloud database error: \(error)")
} else {
print("Sucessfully uploaded to Public Cloud DB")
}
}
I keep getting an error that says:
CKError 0x281ff9ec0: "Network Unavailable" (3/NSURLErrorDomain:-1009); "The Internet connection appears to be offline."
when the cellular connection is definitely not the issue on my device.
I wonder if this might be a setting on the device. Have you checked that iCloud Drive is allowed to use cellular data?
On your iPhone/iPad, go to Settings > Cellular > iCloud Drive (way down at the bottom; make sure it's turned on).
I have configured an always on VPN with a NEOnDemandRuleConnect I retrieve some user data from a backend such as expiration date if the user has paid the subscription. If it expires I'd like to deactivate the VPN without opening the main app, doing it from the Network Extension. I retrieve the data from the backend using a daily timer and then check if the subscription has expired. Then I'd have a function that loads the VPN manager from the system settings app and then deactivate it and finally save it. If I don't deactivate the manager the device will be without connection as it's a VPN that has been configured to connect always with the NEOnDemandRule. The function will be more or less this one
func stopProtection(completion: #escaping (Result<Void>) -> Void) {
NSLog("Called stopProtection")
NETunnelProviderManager.loadAllFromPreferences { (managers, error) in
if let error = error {
NSLog("[SUBS] ERROR \(error)")
}
if let managers = managers {
if managers.count > 0 {
let index = managers.firstIndex(where: { $0.localizedDescription == Constants.vpnBundleId })
guard let index = index else {
completion(.error(ProtectionServiceError.noKidsVpnInstalled))
return
}
let myManager = managers[index]
myManager.loadFromPreferences(completionHandler: { (error) in
guard error == nil else {
completion(.error(ProtectionServiceError.errorStoppingTunnel))
return
}
// Deactivate the VPN and save it
myManager.isEnabled = false
myManager.saveToPreferences(completionHandler: { (error) in
guard error == nil else {
completion(.error(ProtectionServiceError.errorStoppingTunnel))
return
}
completion(.success(()))
})
})
} else {
completion(.error(ProtectionServiceError.errorStoppingTunnel))
}
}
}
}
All this code and logic is being performed in the extension with all the limitations it supposes. Using the previous function I'd only get the first NSLog saying Called stopProtection but it doesn't load any manager. Calling this from the main target it'd work. I don't know if I can load and modify the manager from the extension or it's another way to do it.
Okay, I have debugged the network extension by attaching to the process and looking into the device Console and this error pops up,
NETunnelProviderManager objects cannot be instantiated from NEProvider processes
So nope, there's the answer!
I try to get userRecordID in airplane mode, but I get an error, any other way?
class func asdf() {
var defaultContainer = CKContainer.defaultContainer()
var publicDatabase = defaultContainer.publicCloudDatabase
defaultContainer.fetchUserRecordIDWithCompletionHandler({ userRecordID, error in
if error == nil {
println("userRecordID.recordName : \(userRecordID.recordName)")
} else {
println("\(error.localizedDescription)")
}
})
}
Terminal: Couldn't renew our secure session
I put an accountStatusWithCompletionHandler call outside of fetchUserRecordIDWithCompletionHandler, that returned CKAccountStatus.Available.
You cannot detect internet connectivity with CloudKit. It will only give you an error when there is no connectivity. If you do want to test for internet connectivity, then you could use the famous Reachability class like this: How to check for an active Internet connection on iOS or OSX?
If you want to detect changes to the iCloud account, then you can add the following code to your AppDelegate application didFinishLaunchingWithOptions:
var localeChangeObserver = NSNotificationCenter.defaultCenter().addObserverForName(NSUbiquityIdentityDidChangeNotification, object: nil, queue: NSOperationQueue.mainQueue()) { _ in
println("The user’s iCloud login changed: should refresh all user data.")
}
If you then want to fetch the user id, you have to do a container.requestApplicationPermission to see if you are allowed to query an then a container.fetchUserRecordIDWithCompletionHandler. Bit this requires internet connection. You could cache it on the device together with the detection code above to get the correct status.
I came across to this code, comparing recently and previous logged in user's token, and if the same, use the previously downloaded userRecordID. The only problem that in some cases on my iPad ubiquityIdentityToken method returns nil even dow I am logged in, strange.
class func checkUser() {
let ubiquityIdentityToken = NSFileManager.defaultManager().ubiquityIdentityToken
let status = Utility.status()
let prevUbiquityIdentityToken = status.objectForKey("ubiquityIdentityToken")
if ubiquityIdentityToken != nil && ubiquityIdentityToken!.isEqual(prevUbiquityIdentityToken) {
} else if ubiquityIdentityToken != nil && !ubiquityIdentityToken!.isEqual(prevUbiquityIdentityToken) {
status.setObject(ubiquityIdentityToken!, forKey: "ubiquityIdentityToken")
Utility.saveStatus(status)
let defaultContainer = CKContainer.defaultContainer()
let publicDatabase = defaultContainer.publicCloudDatabase
defaultContainer.fetchUserRecordIDWithCompletionHandler({ userRecordID, error in
if error == nil {
//do some stuff
})
} else {
println("\(error.localizedDescription)")
}
})
} else {
//do some stuff
status.removeObjectForKey("ubiquityIdentityToken")
Utility.saveStatus(status)
}
}