I made a javascript cloud app that runs on a webpage in a webview on my iPad app that communicates via WebSocket connection but it only works when im on my http site and not https or else I get an CFNetwork SSLHandshake failed (-9806) error in Xcode and on the website it says time out during handshake.
Is this because the webserver on the iPad is running on HTTP instead of HTTPS?
JAVASCRIPT CLOUD APP
This part in the cloud is working for HTTP when connecting to the web server on the iPad.
var protocol = "ws";
if (this.useSecureConnection)
protocol = "wss";
var url = protocol+'://localhost:'+this.port+'/service';
this.connection = new WebSocket(url);
Xcode iOS iPad App (Objective-C)
I thought that was the issue so I tried to enable HTTPS but I am not sure what to create for the "sslIdentityAndCertificates" method.
- (BOOL)isSecureServer
{
HTTPLogTrace();
// Override me to create an https server...
return YES;
}
/**
* This method is expected to returns an array appropriate for use in kCFStreamSSLCertificates SSL Settings.
* It should be an array of SecCertificateRefs except for the first element in the array, which is a SecIdentityRef.
**/
- (NSArray *)sslIdentityAndCertificates
{
HTTPLogTrace();
return nil;
}
Some of the other posts I have seen use APIs that are only available on Mac and not iOS.
I tried several combinations of ATS permissions as well. All resulted in HTTPS not allowing for WebSocket connection.
Any help is greatly appreciated! :)
Use case: Android devices cannot contact Ruby On Rails server directly (it is behind firewall) and I cannot have a Internet server to receive requests directly. I need to have internal Rails server to retrieve messages from Android devices and instead of a pooling strategy, I've seen that GCM + XMPP would fit perfectly.
But, I could not find any info on how to code such scenario in Ruby/Rails.
How can I not only send push-notifications from my Ruby On Rails server, but also receive Upstream Messages from GCM (Google Cloud Messaging) connecting my Ruby On Rails server to Google CCS Servers?
for the Upstream, messages are originated from Android device, that is not the scope of the question
I know that I must use XMPP for that.
I know there are ruby gems for sending push-notifications from rails servers to Android devices, but all of them are HTTP based (at least, all that I've seen) and cannot do what I need
I know that Rails server would keep a connection opened (XMPP) to Google's CCS Servers (GCM Cloud Connection Server) to receive Upstream messages
I am aware of XMPP4r gem but cannot find code examples enough to integrate it with Rails
Any help is appreciated.
Log (or what I have done so far...)
17/12/15:
Trying to use this post as a starting point. I have created a project on google console and added a server API key, also enabled API Google Cloud Messaging for Android. I have tested with this code (based on this blog post) and, so far, it executes with no errors:
require 'stella_gcm_xmpp'
id = '[project_number]#gcm.googleapis.com'
password = [API_KEY]
gcm = StellaGcmXmpp.new(id, password, true, true)
gcm.connect
gcm.callback
Upstream Message test
Client Side (out of the scope of the question, for completeness sake):
$ ionic start gcm-test
$ ionic platform add android
$ ionic plugin install cordova-plugin-chrome-apps-gcm
$ ionic run android
open Chrome-Dev-Tools console:
> chrome.gcm.register( ['2195xxxxx718'], function(regId) { console.log('regId:' + regId); } )
> regId:APA91bG_5QIpVrBvuooVp7xO...KiVt3ozcf2HKIkHq_42UAPAU4w
> chrome.gcm.send( {destinationId: '2195xxxxx718#gcm.googleapis.com', messageId: '111', timeToLive: 10, data: {my: 'my message'} }, function(messageId) { console.log(messageId); } )
> 8
Server Side
check receive of upstream message on Ruby (irb) console:
D, [2015-12-18T10:09:05.664007 #4019] DEBUG -- : RECEIVED:
<message from='devices#gcm.googleapis.com' to='2195xxxxx718#gcm.googleapis.com' type='normal'><gcm xmlns='google:mobile:data'>{"data":{"my":"my message"},"time_to_live":86400,"from":"APA91bG_5QIpVrBvuooVp7xOos_EYzA4XNH0CeGzVudbJXxW4avE4NpZO84Q3mC2I-FKAGMTfFdGumSGmkUYViZVwp5gbbC38NDS4GWyaIsABJfhZd3J5KMJBLKgah6lC4LwkbLHKiVt3ozcf2HKIkHq_42UAPAU4w","message_id":"8","category":"com.ionicframework.gcmtest908063"}</gcm></message>
D, [2015-12-18T10:09:05.665623 #4019] DEBUG -- : PROCESSING:
<message from='devices#gcm.googleapis.com' to='2195xxxxx718#gcm.googleapis.com' type='normal' xmlns='jabber:client'><gcm xmlns='google:mobile:data'>{"data":{"my":"my message"},"time_to_live":86400,"from":"APA91bG_5QIpVrBvuooVp7xOos_EYzA4XNH0CeGzVudbJXxW4avE4NpZO84Q3mC2I-FKAGMTfFdGumSGmkUYViZVwp5gbbC38NDS4GWyaIsABJfhZd3J5KMJBLKgah6lC4LwkbLHKiVt3ozcf2HKIkHq_42UAPAU4w","message_id":"8","category":"com.ionicframework.gcmtest908063"}</gcm></message> (Jabber::Message)
D, [2015-12-18T10:09:05.665760 #4019] DEBUG -- : TRYING stanzacbs...
D, [2015-12-18T10:09:05.665859 #4019] DEBUG -- : TRYING message/iq/presence/cbs...
[2015-12-18 10:09:05] GCM send Failed id: 8 error:
*The 'GCM send Failed id: 8 error:' occurs not because of an error, but because message-type is empty*
Downstream Message test (out of the scope of the question, for completeness sake)
Client Side
chrome.gcm.onMessage.addListener(function(msg) { console.log('msg: ' + JSON.stringify(msg)) } )
Server Side
gcm.send 'APA91bG_5QIpVrBvuooVp7x...kHq_42UAPAU4w', '999', { msg: 'teste' }
Client Side
msg: {"data":{"msg":"teste"}}
CCS (GCM's XMPP server) would sit in between your Android clients and your ruby server. Once your ruby server can establish an XMPP connection to CCS then there is nothing special that has to occur to deliver messages from client to server and vice versa. The ruby server would be responsible for sending and receiving messages to and from CCS.
I am implementing iOS app where I have to implement Respoke SDK for audio and video calling. Audio and video functionality is working fine in development mode but In production mode it gives me error "Api authentication error". I have used this code for production:
[self.client connectWithTokenID:[[aryResult valueForKey:#"data"]valueForKey:#"token"] initialPresence:nil errorHandler:^(NSString *errorMessage)
{
[self showError:errorMessage];
}];
For reference, I have used this : Respoke Documentation
Please tell me what is missing in my end. Please help me out.
Thanks a lot in advance!
It seems most likely you are having one of these problems:
The value returned by [[aryResult
valueForKey:#"data"]valueForKey:#"token"] is not exactly the same
as the value returned by the Respoke server when asking for a
brokered authentication token from
https://api.respoke.io/v1/tokens due to URL encoding of the data
between the server and your iOS application or something similar.
The brokered authentication token is only valid for 20 seconds, so
perhaps too much time has passed before your iOS application
attempts to use it.
You have not switched your application out of
development mode on the Respoke developer portal, or have not
created a role to use when authenticating. This documentation
page
explains how to properly set up your application and define a role
for using brokered authentication. You can also use the example code
on that page to make sure that you are getting a valid token for
your application. This would help make sure you have your account
configured correctly.
I have resolved the issue by adding some lines of code. Now for the production mode, code will be this:
if (!sharedRespokeClient)
{
// Create a Respoke client instance to be used for the duration of the application
sharedRespokeClient = [[Respoke sharedInstance] createClient];
}
sharedRespokeClient.delegate = self;
[sharedRespokeClient connectWithTokenID:tokenStringFromServer initialPresence:nil errorHandler:^(NSString *errorMessage) {
[self showError:errorMessage];
}];
I'm new in iOS and Swift development, and i'm not used to manage the network reachability in my usual programs.
I found AFNetworking and Alamofire which are great frameworks to ease the API calls in iOS.
But i have difficulties to figure out how to make some requests to wait until network is back if i'm loosing it.
Typically during session login or getting some json lists or downloading images.
Do you have some tutorials or examples i can rely on to improve my knowledge and be able to build a strong application resilient to network availability ?
now Alamofire has just included a Network status listener
https://github.com/Alamofire/Alamofire/pull/1053
Alamofire now has a network reachability manager
This is from their github page -
let manager = NetworkReachabilityManager(host: "your.server.url.com")
manager?.listener = { status in
print("Network Status Changed: \(status)") }
manager?.startListening()
I am developing a kind of gaming application where I need to handle the following:
`if(user used siri app)
{
// Send notification:1 to server
}
elseif(user attended a call)
{
// Send notification:2 to server
}`
Does it possible to handle above cases inside my app ? Please guide me.
Thanks in Advance.
I am aware of applicationDidEnterBackground which can be used when app is sent to backgound.
But it will be great if I can find abouve cases.
No. This information is not available to an app.