iOS: XMPP Reconnect with Old School SSL connection - ios

XMPPFramework provides an extension named XMPPReconnect for "accidental disconnections" and automatically reconnects the stream.
This works well on the setting of the normal connection:
[xmppStream connect:&error]
[xmppStream setHostPort:5222];
allowSelfSignedCertificates = NO;
allowSSLHostNameMismatch = NO;
but not for this Old School SSL connection:
[xmppStream oldSchoolSecureConnect:&error]
[xmppStream setHostPort:5223];
allowSelfSignedCertificates = YES;
allowSSLHostNameMismatch = YES;
The error libxmlErrorDomain as error code 4 with the description Document is empty was thrown continuously,
sometimes, the error GCDAsyncSocketErrorDomain as error code 4 with description Read operation timed out also thrown.
Please suggest me the way to make the XMPPReconnect work on the Old School SSL connection.
P.S. The XMPP server is openfire and the PLAIN mechanism for authentication.

I don't think the Reconnect Extension of the XMPPFramework knows about old school ssl connection. IMHO you will have to modify 'XMPPReconnect.m' function 'maybeAttemptReconnectWithReachabilityFlags:' to do something like:
if(self.usesLegacyConnect)
[xmppStream oldSchoolSecureConnect:nil];
} else {
[xmppStream connect:nil];
}

Related

iOS Pusher doesn't work, client not connecting

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 ...];
...

Setting up XMPPFramework for iOS

I am working on an iOS app with a chat function. I want to know if there is any resource to configure the XMPPFramework in order to connect my iOS app with Openfire server.
I am new to XMPP Protocol.
I am currently learning about XMPP Stream and Rosters but I need to at least get the connection to work.
Please help.
To get yourself started, dive into the sample iOS project in XMPPFramework-master > Xcode > iPhoneXMPP.
Preferably, begin tweaking in the project itself, and get your understanding from there before moving on to create your own XMPP project.
Basically to connect XMPP to OpenFire server, most of the configurations lie in AppDelegate.
Set your OpenFire server's details in the XMPP setup:
- (void)setupStream
{
...
// Specify your server's IP address
[xmppStream setHostName:#"123.12.123.12"];
// Specify your host port
[xmppStream setHostPort:5222];
}
Assuming you have already created a contact in your OpenFire's roster, set a contact's credentials in the XMPP connection method:
- (BOOL)connect
{
/**
* Of course, do not hardcode in an actual implementation
* Appending the server name at the back of user ID is necessary
*/
myJID = #"user#openfire";
myPassword = #"password goes here";
}
Ensure you call the connect method in app launch method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self connect];
}
Ensure you are connected here:
- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
NSLog(#"User Connected");
// You are connected to the server at this point.
}
Ensure you are authenticated here:
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
NSLog(#"User Authenticated");
/**
* Once you've reached this point,
* Check your server for the online users.
* You should now be seen as "available".
* Cheers!
*/
}

NSURLConnection Error code (-1202,1012)

I am using NSURLConnection for one field service type iOS appliation, so app is field service type there are more then 50 users and more then 50 users may use the application on same time that's why there are more then 50 or 60 request come to the server. Now my issue is I have received below two errors frequently means every single user can face this error more then 5 times in one day. so it become a challenge for me.
The Error Code:
-1202 NSURLErrorServerCertificateUntrusted
-1012 NSURLErrorUserCancelledAuthentication
I have searched a lot and i found that they are server related errors but still i don't have any solution for how to resolve this problem.
Please help me how can i solve this NSURLConnection error (-1202 NSURLErrorServerCertificateUntrusted and -1012 NSURLErrorUserCancelledAuthentication) problem.
Thanks in advance.
You need to use connectionWithRequest:delegate: to accept untrusted certificates.
You can implement these delegate methods
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
return YES;
}
- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection
{
return YES;
}

Trouble connecting to a google apps server via MailCore

I'm trying to connect to Google Apps email server via IMAP. The code I am using below, every time I try to connect I get the error: Parse error Anyone know the source of this error?
int port = 993;
CTCoreAccount *account = [[CTCoreAccount alloc] init];
BOOL success = [account connectToServer:#"imap.gmail.com"
port:port
connectionType:CTConnectionTypeStartTLS
authType:CTImapAuthTypePlain
login:login
password:password];
NSLog(#"Port: %d",port);
if (!success) {
NSLog(#"Connection failed, error: %#",[account.lastError localizedDescription]);
}
else {
NSLog(#"Connection succeeded");
}
There were two issues simultaneously going on here. The first was that my network had a firewall and that was the source of the Parse Error.
Second, when you need to connect to Google Maps IMAP server, you'll need to use the CTConnectionTypeTLS instead of CTConnectionTypeStartTLS, because the second one makes the server go bonkers.

TURN Connection using the iOS XMPPFramework and an OpenFire Server

Problem : How can I get a successful TURN Connection using the iOS XMPPFramework and an OpenFire Server. I want to be able to send and recieve files.
Note : The base of my code is from the following tutorial : http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-server-setup/
Update 13th April 2012 : After more research, I think the real relevant code I need to display in this question is this ...
This is where the TURNSocket attempts to connect
XMPPJID *jid = [XMPPJID jidWithString:#"myFriendsUsername#beta.myCompany.co.uk"];
NSLog(#"Attempting TURN connection to %#", jid);
TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:[self xmppStream] toJID:jid];
[turnSockets addObject:turnSocket];
[turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
[turnSocket release];
However, when I debug through the code, in TURNSocket I get to a comment which states that "We were unable to find a single proxy server from our list". This is because the Array 'streamhosts' never gets populated. What could be the issue? Is there some XML somewhere that should tell me the problem? Is the issue likely to be with OpenFire?
The problem is caused if a full jID with a resource is not provided to TurnSocket.m! This is passed in in viewDidLoad of SMChatViewController
e.g Use
friendsUsername#beta.myCompany.co.uk/spark
rather than
friendsUsername#beta.myCompany.co.uk
My progress on this project can be followed here
This is the class method of TURNSocket you call to
populate the proxy candidates of the TURNSocket
stream host. So you should put streamhost back to
what it was before stream-host.
+ (void)setProxyCandidates:(NSArray *)candidates;
[TURNSocket setProxyCandidates:#["host1.somedomain.com", #"host2.someotherdomain.com"]];
In processRequestResponse.m in TurnSocket, the name of the streamhost element wasn't what OpenFire was giving me. I have changed it from this
NSXMLElement *streamhostUsed = [query elementForName:#"streamhost-used"];
to this
NSXMLElement *streamhostUsed = [query elementForName:#"streamhost"];
However, I now have a new error which I am starting a new question for ... OpenFire/XMPP 503 service-unavailable error (XEP-0065 using iOS XMPPFramework)
Update 20/4/2012 : I now believe this answer is wrong! If it was working correctly, streamhostUsed would be there, rather than streamhost with an error!

Resources