iOS Pusher doesn't work, client not connecting - ios

This is for www.pusher.com.
iOS lib they provided is libPusher. After I installed and follow the first step, it just not working. I've heard a few people make it work. Is this library still alive or it doesn't support newer version of iOS?
PTPusher *client = [PTPusher pusherWithKey:#"app-key" delegate:self encrypted:NO]; // I assume this is "key" not "secret" there.
[client connect];
PTPusherChannel *channel = [client subscribeToChannelNamed:#"test"];
NSLog(#"Channel: %#, %d", channel, channel.isSubscribed);
I've implemented delegate methods to track status. After [client connect] called, the delegate method: - (BOOL)pusher:(PTPusher *)pusher connectionWillConnect:(PTPusherConnection *)connection trigged, but then nothing happened after this. No error messages, no success messages. Since the clint is not connecting, the channel is not subscribed either.
I've implemented pusher on JS and it worked. Since what I did is very basic client connection and there is nothing I can do about (At least from documents), so I assume maybe this library just not working anymore.

I was being dumb and ignored that the document said pusher client should be strong. Therefore, the solution should be:
#property(nonatomic) PTPusher *client;
self.client = [PTPusher ...];
...

Related

ConnectionID is in incorrect formate. SignalR

I usesignalR latest library. I downloaded signalR library from gitHub SignalR gitHub link and installed pod file in my app. I am working on iOS end. I don't know about asp.net. The only url is provided to me for integration. Here is my code
__weak SRConnection *connection = [SRConnection connectionWithURL:SIGNALR_PATH];
[connection addValue:[[NSUserDefaults standardUserDefaults] objectForKey:kAccessToken] forHTTPHeaderField:#"MyAuthentication"];
connection.received = ^(NSString * data) {
NSLog(#"%#",data);
};
connection.started = ^{
[connection send:#"hello world"];
};
[connection start];
Connection open successfully but When I get try to send message it gives me an error "The ConnectionId is in incorrect format".
I am using latest library of signalR. I don't know what I need to authorised. Is only url enough for that? Or will need to add accessToken that I get on login?.
Please help me what I need for integrating signalR. I searched a lot but couldn't find any clear information.

Twilio TCDevice connect timeout

I am wondering if there is a way to change the timeout on the outgoing call from [TCDevice -connect:delegate] in the Twilio iOS client. I have tried playing with different key/value pairs in the connect options NSDictionary but nothing seems to have an effect.
Megan from Twilio here.
For using timeout from the mobile client, you can embed the timeout parameter in the connect:delegate: method of TCDevice:
https://www.twilio.com/docs/api/client/ios/TCDevice#connectDelegate
For example:
NSDictionary *params = #{#"timeout": #"10"};
self.connection = [self.device connect:params delegate:self];
It sounds like you were trying this, but maybe missed to get this timeout argument in your TwiML app and add it into the response which is eventually sent to HUrl.

how to configure socket io in server to get acknowledge (SocketIOCallback) from ios socket

I am developing a chat app in ios with node.js and socket.io. I use SocketIOCallback to send acknowledgement. But i don't getting any acknowledgement on server.js. Here is the code i use to send acknowledge
SocketIOCallback cb = ^(id argsData) {
NSDictionary *response = argsData;
// do something with response
NSLog(#"ack arrived: %#", response);
};
[socketIO sendEvent:#"message" withData:values andAcknowledge:cb];
server.js
socket.on('message', function(postMessage,callback){
console.log(callback);
//callback('okkk');
console.log('username-->'+ socket.username);
console.log('ID-->'+ socket.id);
io.sockets.emit("pvt",socket.username,postMessage+socket.username);
io.sockets.emit("pvt",socket.username,postMessage+socket.username);
});
when printing console.log(callback) it show unknown in terminal
How to configure server.js to get these acknowledgement from ios app. Or how to send acknowledgement from server to ios app and vice versa Please help me to solve these problem with example. Thanks in advance
I found a solution which consists on changing emit method to emitEvent. Hope it really help you.

How to check status of web server in iOS?

I need to check status of web server, specifically, the information if the web server returns proper status code 200. Is there any way to get the HTTP response code from web server in iOS?
This is well documented in the official docs, with no need to implement a 3rd party library (although if you're new to iOS coding, a Networking API can simplify the underlying function calls). Your class must be an NSURLConnection delegate, and after making the NSURLConnection you implement the delegate method something like this:
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse*)response
{
if ([response statusCode] == 200) {
// Handle valid response (You can probably just let the connection continue)
}
else {
// Other status code logic here (perhaps cancel the NSURLConnection and show error)
}
}
You should find the URL Loading Guide very useful reading for this and other networking functions on iOS.

How to make webservice pass errors through NSURLConnection's connection:didFailWithError:?

What does a web service need to do to cause NSURLConnection's delegate to receive the connection:didFailWithError: message?
For example:
iOS app passes a token to the web service, web service looks up the token, and then the web service needs to respond with an error saying "invalid token" or something of the like.
Currently, the data is received, and in "connectionDidFinishLoading:" is parsed for error messages. This means I'm error checking in two places, which I am trying to avoid.
I have both the iOS app and web service completely under my control.
In my experience (the three most dangerous words in programming), -connection:didFailWithError: is only called if the HTTP exchange failed. This is usually a network error or maybe an authentication error (I don't use authentication). If the HTTP message succeeds, no matter the response code, -connectionDidFinishLoading: is called.
My solution: call -connection:didFailWithError: when I detected an error. That way all my error handling code is in one place.
At the top of my -connectionDidFinishLoading:, I have:
NSError *error;
NSDictionary *result = [self parseResultWithData:self.connectionData error:&error];
if (!result) {
[self connection:connection didFailWithError:error];
return;
}
There are many conditions on which the delegate connection:didFailWithError: of NSUrlConnection may invoke.Here's a list of those errors or constants.I think an alertview would be better to show http errors in connection:didFailWithError:.
-(void) connection:(NSURLConnection *)connection didFailWithError: (NSError *)error
{
UIAlertView *errorAlert= [[UIAlertView alloc] initWithTitle: [error localizedDescription] message: [error localizedFailureReason] delegate:nil cancelButtonTitle:#"Done" otherButtonTitles:nil];
[errorAlert show];
[errorAlert release];
NSLog (#"Connection Failed");
}
While not directly related to your question, I would encourage you to move to a more high level library. I can heartily recommend AFNetworking, it is production ready and I have used it in many projects. This will allow you to inspect the response code of each request in the failure block. This project also abstracts away a lot of the low level handling that you would otherwise be required to write for network communication; I'm speaking here about parsing and creating XML / JSON strings to communicate with a service.
To give you a more focused answer to your question, I would call the cancel method of your NSURLConnection once you have noticed an error in connectionDidFinishLoading:. This will automatically cancel the request and call the failure method of the delegate object.
The documentation for NSURLConnection is pretty dry, and the failure method of the delegate does not specifically document the failure cases. You may be able to find more information in the URL Loading System Programming Guide.
I couldn't see the forrest for the trees.
I needed to step back from connection:didFailWithError: and look at a different delegate method connection:didReceiveResponse:!!
With the web service fully under my control, the endpoint could respond with a 500 status code, which gets picked up in connection:didReceiveResponse, and pass along some JSON further explaining the situation, which gets picked up and processed in connection:didReceiveData:.
The NSURLConnection delegate hangs onto a couple more bits of state throughout the process, but it has the best code smell I've found so far.
Jeffery's answer was by far most correct: the connection:didFailWithError: callback is only in relation to the network failing, any response from the web service means the connection didn't fail!

Resources