iOS Troubleshooting when server uses a self-signed certificate Swift 3

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

iOS Troubleshooting when server uses a self-signed certificate Swift 3

Polina Koleva
Hey,
I am trying to run Swift 3 HelloWorld app (HelloWorldSwift) but I have a problem with the self-signed certificate.
Looking at the documentation (ios troubleshooting) and changing it a little bit for Swift 3 , I added in my DeviceRegistration.swift file the method:

public func urlSession(_session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust && challenge.protectionSpace.host == serverURL.host! {
            let credentials = URLCredential(trust: challenge.protectionSpace.serverTrust!)
            completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, credentials)
        } else {
            completionHandler(Foundation.URLSession.AuthChallengeDisposition.cancelAuthenticationChallenge, nil)
        }
    }

But it still doesn't work. The method is not invoked at all. Do I miss something?

Any help will be appreciated.

Polina
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Aerogear-users] iOS Troubleshooting when server uses a self-signed certificate Swift 3

Julio Cesar Sanchez Hernandez
Hi.

There is something missing on the email you sent.

You said
I added in my DeviceRegistration.swift file the method:

But nothing appears, not sure if the mail client removed the code.

Do you see any error message on Xcode console? If yes, share them.

Do you have a paid Apple developer account? Push notifications don't work on free accounts.
Are you testing on a real device? Push notifications don't work on simulator.
Is the device asking for the push permissions?

Is your server available online so I can take a look?



On Mon, May 29, 2017 at 2:57 PM, Polina Koleva <[hidden email]> wrote:
Hey,
I am trying to run Swift 3 HelloWorld app ( HelloWorldSwift
<https://github.com/aerogear/aerogear-ios-cookbook/tree/master/UnifiedPushHelloWorld>
) but I have a problem with the self-signed certificate.
Looking at the documentation ( ios troubleshooting
<https://aerogear.org/docs/unifiedpush/aerogear-push-ios/guides/#troubleshooting>
) and changing it a little bit for Swift 3 , I added in my
DeviceRegistration.swift file the method:



But it still doesn't work. The method is not invoked at all. Do I miss
something?

Any help will be appreciated.

Polina



--
View this message in context: http://aerogear-users.1116366.n5.nabble.com/iOS-Troubleshooting-when-server-uses-a-self-signed-certificate-Swift-3-tp1115.html
Sent from the aerogear-users mailing list archive at Nabble.com.
_______________________________________________
Aerogear-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/aerogear-users


_______________________________________________
Aerogear-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/aerogear-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Aerogear-users] iOS Troubleshooting when server uses a self-signed certificate Swift 3

Polina Koleva
Hey :)
Julio Cesar Sanchez Hernandez wrote
Hi.

There is something missing on the email you sent.

You said
I added in my DeviceRegistration.swift file the method:
I have added the code but it is not visible in the email. I place it here again (hopefully this time it will work). So this is the implementation of the method:

public func urlSession(_session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust && challenge.protectionSpace.host == serverURL.host! {
            let credentials = URLCredential(trust: challenge.protectionSpace.serverTrust!)
            completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, credentials)
        } else {
            completionHandler(Foundation.URLSession.AuthChallengeDisposition.cancelAuthenticationChallenge, nil)
        }
    }


Julio Cesar Sanchez Hernandez wrote
Do you see any error message on Xcode console? If yes, share them.
Yes, it is written that the server is not trusted because of the self-signed certificate.
This is the error:

Error Registering with UPS: The certificate for this server is invalid. You might be connecting to a server that is pretending to be “x.x.x.x” which could put your confidential information at risk.

Julio Cesar Sanchez Hernandez wrote
Do you have a paid Apple developer account?
 Yes, I have a developer account.

Julio Cesar Sanchez Hernandez wrote
Are you testing on a real device?
Yes, I am testing on a real device.

Julio Cesar Sanchez Hernandez wrote
Is the device asking for the push permissions?
Yes, the app asks for permission to receive push notifications. But it cannot connect to the server.

Julio Cesar Sanchez Hernandez wrote
Is your server available online so I can take a look?
No, I am running the ups on my local machine.

Thanks.
On Mon, May 29, 2017 at 2:57 PM, Polina Koleva <[hidden email]>
wrote:

> Hey,
> I am trying to run Swift 3 HelloWorld app ( HelloWorldSwift
> <https://github.com/aerogear/aerogear-ios-cookbook/tree/
> master/UnifiedPushHelloWorld>
> ) but I have a problem with the self-signed certificate.
> Looking at the documentation ( ios troubleshooting
> <https://aerogear.org/docs/unifiedpush/aerogear-push-ios/
> guides/#troubleshooting>
> ) and changing it a little bit for Swift 3 , I added in my
> DeviceRegistration.swift file the method:
>
>
>
> But it still doesn't work. The method is not invoked at all. Do I miss
> something?
>
> Any help will be appreciated.
>
> Polina
>
>
>
> --
> View this message in context: http://aerogear-users.1116366.
> n5.nabble.com/iOS-Troubleshooting-when-server-uses-a-self-signed-
> certificate-Swift-3-tp1115.html
> Sent from the aerogear-users mailing list archive at Nabble.com.
> _______________________________________________
> Aerogear-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/aerogear-users
>

_______________________________________________
Aerogear-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/aerogear-users
Loading...