Failed to connect HydraSDK - swift

I'm using HydraSDK to create VPN app. I logged in successfully, get country (servers) list and when try to connect to closest server I receive error
Restart VPN error: Error Domain=com.anchorfree.hydra.manager Code=4
"failed_to_connect"
UserInfo={NSLocalizedDescription=failed_to_connect}
I'm using this code to start VPN
private func startVPN() {
self.hydraClient.start(location: nil) { (e, _) in
if let ex = e {
print("Restart VPN error: \(ex)")
} else {
print("Restart VPN success, country: \(self.country?.code ?? "unknown")")
}
}
}

Problem was in extension info.plist

Related

macOS network extension - activate vpn provider failed on startVPNTunnel

I'm trying to start the vpn provider from a container application
After I successfully activated the extension, and started the process by sending xpc request to the network extension, I've tried to load the provider and start getting notifications about handleNewFlow
I use the following callback to signal process has started, in order to start the configuration phase.
extension NetworkExtensionManager: OSSystemExtensionRequestDelegate {
...
func request(_ request: OSSystemExtensionRequest,
didFinishWithResult result: OSSystemExtensionRequest.Result) {
...
After loadAllPreferences, I've set the manager from which I'd like to load the provider:
NEAppProxyProviderManager.loadAllFromPreferences { [self] (managers, error) in
assert(Thread.isMainThread)
if let error = error {
print(error.localizedDescription)
} else {
let manager = managers?.first ?? NEAppProxyProviderManager()
let proto = (manager.protocolConfiguration as? NETunnelProviderProtocol) ?? NETunnelProviderProtocol()
proto.serverAddress = "myHost"
proto.providerBundleIdentifier = "myExtensionBundle"
proto.providerConfiguration = ["key": "val"]
manager.localizedDescription = "myApp"
manager.protocolConfiguration = proto
manager.isEnabled = true
Then I extract the connection out of the manager and use it to start the tunnel provider (hopefully this operation will create a new item under System Preferences --> Network)
let session = manager.connection as! NETunnelProviderSession
do {
os_log(" manager.connection status: \(session.status.rawValue)")
try session.startVPNTunnel(options: nil)
}
catch {
os_log("failed to initProviderManager app proxy provider, \(error.localizedDescription)")
print(error)
}
However, I've got the following error message from the exception thrown out of this line session.startVPNTunnel :
failed to initProviderManager app proxy provider, The operation couldn’t be completed. (NEVPNErrorDomain error 1.)
Looking for the error name I found this NEVPNErrorConfigurationInvalid
Perhaps you can help me figure out where I go wrong in my attempt to start the tunnel provider ?
Thanks !

How to detect and handle firebase Permission Denied error code with swift

I am getting the following error while observe data from firebase realtime database. What I want to do is if the error is Permission Denied, I want to do a different action. How can I tell if the error is Permission Denied?
error :
Optional(Error Domain=com.firebase Code=1 "Permission Denied" UserInfo={NSLocalizedDescription=Permission Denied})
mycode:
func observeData(completion: #escaping (Bool) -> Void){
Database.database().reference().child("values").observe(.value, with: { (snap) in
completion(true)
}){ (error) in
let errorCode = (error as NSError).code
if errorCode == .?????? { //-->> what to come here
self.anotherFunc() //--> if Permission Denied call this func
completion(false)
}else{
completion(true)
}
}
}
This is what I did for Auth errors in my firebase app. Not sure if it will work in your context, but you might find it useful.
func firebaseErrorParser(error: Error) -> String? {
if let errorCode = AuthErrorCode(rawValue: error._code) { // <- here!!
switch errorCode { // switch case
case .invalidVerificationCode:
return "Wrong code or phone number!"
default:
return "An error occured... "
}
} else {
return nil
}
}
I only had one entry in my switch/case because the only error I wanted to give specific feedback to the user about was if the user entered the wrong phone number. It seems like you can do something similar with firestore permissions errors

Stuck when connect to server when using xmppFramework

I started with xmppFramework with iOS and locally ejabberd server (running on "localhost:5280"). I logged in ejabberd server by using "username: admin, password: admin"
I checked my code correctly and add delegate "XMPPStreamDelegate".
I face problem that my code call the delegate function "xmppStreamWillConnect" but it didn't call "xmppStreamDidConnect".
Genrally, what may cause this issue?
My code:
func connect() {
if !self.xmppStream.isDisconnected() {
return
}
self.xmppStream.hostName = "localhost:5280"
self.xmppStream.myJID = XMPPJID(string:"admin#localhost")
try! self.xmppStream.connect(withTimeout: 10)
if self.xmppStream.isConnected(){
print(true)
}
self.xmppStream.startTLSPolicy = XMPPStreamStartTLSPolicy.required
self.xmppStream.supportsStartTLS()
print("ok")
}
func xmppStreamWillConnect(_ sender: XMPPStream!) {
print("will connect ")
}
func xmppStreamDidConnect(_ stream: XMPPStream!) {
print("Stream: Connected")
try! stream.authenticate(withPassword: self.password)
}
The result of printing is :
ok
willConnect
If you make localhost, surly it will not work.
Simulator will run on the localhost and you cannot run both on the same localhost.

CKContainer.discoverAllIdentities always fails

The CKContainer.discoverAllIdentities request always fails in my CloudKit app. It has continually failed over the course of several days.
A simplified version of the code that is failing (which results in the same error) is:
private func getContacts(completion: (([CKUserIdentity]?) -> Void)?) {
container.status(forApplicationPermission: .userDiscoverability) { [weak self] status, error in
if let error = error {
print(error)
}
switch status {
case .granted:
self?.discover(completion: completion)
default:
print("status not granted")
}
}
}
private func discover(completion: (([CKUserIdentity]?) -> Void)?) {
let op = CKDiscoverAllUserIdentitiesOperation()
op.qualityOfService = .userInitiated
op.discoverAllUserIdentitiesCompletionBlock = { error in
if let error = error {
print(error)
}
}
op.userIdentityDiscoveredBlock = { identity in
print(identity)
}
op.start()
}
It results in an error being passed to the op.discoverAllUserIdentitiesCompletionBlock. The description of the error in the log is:
<CKError 0x1c4a51a60: "Server Rejected Request" (15/2000); server message = "Internal server error"; uuid = F67453B9-712D-4E5E-9335-929123E3C978; container ID = "iCloud.com.huntermaximillionmonk.topdraw">
Previously, this operation would work, but only for certain iCloud users. Now it's not for both of my test users.
Problem:
This was a problem in iOS 11.0
Based on my testing:
This works ok in Xcode 9.2 / iOS 11.2.1 on the device (not simulator)
After resetting the simulator works for the first time, doesn't work subsequently, however on the device it works repeatedly.
Code:
let queue = OperationQueue()
func requestPermissions(for permissions: CKApplicationPermissions,
completionHandler: #escaping (CKApplicationPermissionStatus, Error?) -> ()) {
CKContainer.default().requestApplicationPermission(permissions) { status, error in
if let error = error {
print("Error for requesting \(permissions) - \(error)")
}
let statusMessage : String
switch status {
case .granted:
statusMessage = "Granted"
case .denied:
statusMessage = "Denied"
case .couldNotComplete:
statusMessage = "Could not complete"
case .initialState:
statusMessage = "Initial state"
}
print("Permission - \(statusMessage)")
completionHandler(status, error)
}
}
private func discoverAllUsers() {
let operation = CKDiscoverAllUserIdentitiesOperation()
operation.userIdentityDiscoveredBlock = { userIdentity in
print("userIdentity = \(userIdentity)")
}
operation.discoverAllUserIdentitiesCompletionBlock = { error in
if let error = error {
print("Discover all users Error: \(error) ")
}
else {
print("Discover all users completed successfully")
}
}
queue.addOperation(operation)
}
Edit:
Apple fixed this issue day after this answer was posted, coincidence?! I don't think so :)
This is not actually the answer to the question, but a fix that helped me to cross over this error. It will require you to change your app UI interaction and add ContactsUI framework to your project, moreover your user will be responsible for selecting a contact with iCloud related email.
Good news is that the method discoverUserIdentity is still works. So, you can use it to get CKUserIdentity from manually selected contact.
func addContact(_ contact:CNContact) {
var lookUpEmails = [CKUserIdentityLookupInfo]()
for email in contact.emailAddresses {
lookUpEmails.append(CKUserIdentityLookupInfo(emailAddress: (email.value as String)))
}
let checkUserOperation = CKDiscoverUserIdentitiesOperation()
checkUserOperation.userIdentityLookupInfos = lookUpEmails
checkUserOperation.userIdentityDiscoveredBlock = { [unowned self] (identity, info) -> Void in
if identity.hasiCloudAccount {
if let recordID = identity.userRecordID {
//do something with discovered user
}
checkUserOperation.cancel()
}
}
checkUserOperation.queuePriority = Operation.QueuePriority.high
CKContainer.default().add(checkUserOperation)
}
It might sound useless, but in my case, it helped me to solve the Server Rejected Request" (15/2000) error, to fix one of the features of my app and continue to use the other feature related code with less efforts than I thought.
I hope someone will find this helpful.
Just another data point on this that might help with the overall picture. I was still seeing this error on 11.2.5 when I used my own iCloud AppleID (with hundreds of contacts) while running a Test App that called discoverAllIdentitiesWithCompletionHandler. I'd get the dreaded
CKError 0x1c0051730: "Server Rejected Request" (15/2000); server message = "Internal server error".
When I switched to run the exact same code on my daughters iOS11.2.5 device (with just a handful of contacts) the code worked fine.
Leads me to believe there is some rate limiting going on when there are a lot of contacts with iOS11.
(P.S. No errors at all running on iOS10)

Firebase Storage Upload Error: FIRStorageErrorDomain Code=-13000

I am trying to upload an image to Firebase and I actually succeeded several times yesterday, but today I'm getting this error:
Optional
- Some : Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response." UserInfo={ResponseErrorDomain=FIRStorageErrorDomain, object=ProfileImages/ascascasc ascas.jpg, error_name=ERROR_USER_NOT_FOUND, bucket=ichallenge-c52ae.appspot.com, ResponseErrorCode=-13020, NSLocalizedDescription=An unknown error occurred, please check the server response.}
I want to reiterate: nothing was changed in the code between yesterday and today, it just stopped working. This is the code, I've highlighted the line where it happens with a comment:
#IBAction func signUpButtonPressed(sender: AnyObject)
{
// If textfields have more than 3 characters
if firstNameTextField.text!.characters.count > 3 && passwordTextField.text!.characters.count > 3 && emailTextField.text!.containsString("#")
{
createUser()
//Goes to Main Storyboard
parseOutdated.signUpInBackgroundWithBlock { (success: Bool, error: NSError?) in
NSNotificationCenter.defaultCenter().postNotificationName("Login", object: nil)
}
}
else
{
firstNameShake.shakeAnimation()
lastNameShake.shakeAnimation()
passwordShake.shakeAnimation()
emailShake.shakeAnimation()
}
}
func createUser()
{
//Unwrap optionals before pushing to Firebase Database
let name: String = "\(self.firstNameTextField.text!) \(self.lastNameTextField.text!)"
storeProfileImage(name)
}
func storeProfileImage(name: String)
{
let profileImageData = UIImageJPEGRepresentation(self.profileImageView.image!, 1.0)
// Create a reference to the file you want to upload
let profileImageRef = storageRef.child("ProfileImages/\(name).jpg")
// Upload the file to the path defined above
profileImageRef.putData(profileImageData!, metadata: nil) { metadata, error in
if (error != nil) //ERROR HAPPENS HERE
{
print("Image not stored: ", error?.localizedDescription)
}
else
{
//Stores the profile image URL and sends it to the next function
let downloadURL = metadata!.downloadURL()
self.storeUserData(name, profileImageURL: downloadURL!)
}
}
}
Here's a screenshot of the breakpoint in XCode:
Any help provided would be deeply appreciated.
If you have been testing with the same user witout signing out on your app, your authentication token might have expired. Try signing out firs