Hi I am working with the xmpp framework working fine till yesterday But I don't know what happen suddenly xmpp didDisConnect method calling
- (void)xmppStreamDidDisconnect:(XMPPStream *)sender withError:(NSError *)error
where I am missing.I know if username password wrong then it will be disconnected.But I checked my username it is fine and it is showing below error
Error Domain=GCDAsyncSocketErrorDomain Code=4 "Read operation timed out" UserInfo={NSLocalizedDescription=Read operation timed out
below is the connect method
- (BOOL)connect
{
if (![xmppStream isDisconnected]) {
return YES;
}
myJID =[NSString stringWithFormat:#"%##servername",[[NSUserDefaults standardUserDefaults] stringForKey:#"FinalUserNameJID"]];
NSString *password1=[[NSUserDefaults standardUserDefaults] stringForKey:#"smsVerificationNumber"];
// If you don't want to use the Settings view to set the JID,
// uncomment the section below to hard code a JID and password.
//
// myJID = #"user#gmail.com/xmppframework";
// myPassword = #"";
if (myJID == nil || password1 == nil) {
return NO;
}
[xmppStream setMyJID:[XMPPJID jidWithString:myJID]];
password = password1;
NSError *error = nil;
if (![xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error connecting"
message:#"See console for error details."
delegate:nil
cancelButtonTitle:NSLocalizedString( #"O_K", #"OK")
otherButtonTitles:nil];
[alertView show];
DDLogError(#"Error connecting: %#", error);
return NO;
}
return YES;
}
Please help me if any body face this issue.Thankyou
Related
I'm using the following logic to check if touchID is available on iPhone and based on the returned value, I direct the user to enroll in touchID or navigate them to setup a PIN. It works fine in the happy path, but if I have even one fingerprint enrolled but have disabled touchID option from iPhone system settings, then it still returns true and navigates user to setup touchID. If I remove all fingerprints, then it works as expected by returning false and navigating to PIN screen.
- (BOOL) isTouchIDAvailable {
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
if (![myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
NSLog(#"Touch ID checking error: %#", [authError localizedDescription]);
return NO;
}
return YES;
}
I've referred to some questions on stack and apple dev docs
Not sure what I'm missing? Appreciate any help. Thanks in advance :)
let context = LAContext()
var error: NSError?
if #available(iOS 9.0, *) {
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
//this is for success
}else{
//error.description for type error LAError.biometryLockout, .biometryNotEnrolled and other errors
}
}
it's not possible. if you have TouchID, you have touchID. But if you want, you can disabled with programaticly. Look at the below code snippet to check touchID is aviable or not.
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = [NSString stringWithFormat:#"Login With your fingerprint with : %#",username];
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
// [self performSegueWithIdentifier:#"Success" sender:nil];
[self loginWithFingerprint];
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
/*
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:error.description
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[alertView show];
*/
// Rather than show a UIAlert here, use the error to determine if you should push to a keypad for PIN entry.
});
}
}];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
/*
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:authError.description
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[alertView show];
*/
// Rather than show a UIAlert here, use the error to determine if you should push to a keypad for PIN entry.
});
}
I'm trying to set up an anonymous login so my users don't have to create an account an account on the eJabberd server to use the chat room. The configuration for the server in the ejabberd.cfg is:
{host_config, "bubble", [{auth_method, anonymous},
{anonymous_protocol, login_anon}]}.
My method to connect the client to the XMPPStream:
- (BOOL)connect {
[self setupStream];
if (![self.xmppStream isDisconnected]) {
return YES;
}
if (![PFUser currentUser]) {
return NO;
}
NSString *currentUserId = [NSString stringWithFormat:#"%##bubble",[PFUser currentUser].objectId];
[self.xmppStream setMyJID:[XMPPJID jidWithString:currentUserId]];
self.xmppStream.hostName = kJABBER_HOSTNAME;
NSError *error = nil;
if (![self.xmppStream connectWithTimeout:10 error:&error]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:[NSString stringWithFormat:#"Can't connect to server %#", [error localizedDescription]]
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
return NO;
}
return YES;
}
As well as the xmppStreamDidConnect method:
- (void)xmppStreamDidConnect:(XMPPStream *)sender {
self.isOpen = YES;
NSError *error = nil;
if(![self.xmppStream authenticateAnonymously:&error]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:[NSString stringWithFormat:#"Can't connect to server %#", [error localizedDescription]]
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
}
}
When I try to login into the server, it keep on getting "The server does no support anonymous authentication".
Not sure what I'm doing wrong here, please let me know your thoughts.
From the XMPPFramework documentation:
If you wish to use anonymous authentication, you should still set myJID prior to calling connect. You can simply set it to something like "anonymous#domain", where "domain" is the proper domain. After the authentication process, you can query the myJID property to see what your assigned JID is.
Make sure that the settings on the server allow anonymous login as well.
If you don't have access to the serve configuration you can still check if the server allows anonymous login using something like:
- (void)xmppStreamDidConnect:(XMPPStream*)sender
{
self.isXmppConnected = YES;
if ([self.xmppStream supportsAnonymousAuthentication]) {
NSError* error = nil;
//the server does support anonymous auth
[self.xmppStream authenticateAnonymously:&error];
}
else {
NSLog(#"The server does not support anonymous authentication");
}
}
Be sure to place it in the didConnect delegate method, as it needs to be connected first.
I am using Parse in my application. I am try to login with Facebook. But I have faced one strange issue. If I am login in Facebook account from my iPhone's settings, then I am getting following error.
Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. (com.facebook.sdk error 2.)" UserInfo=0x17560700 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginCancelled, com.facebook.sdk:ErrorInnerErrorKey=Error Domain=com.apple.accounts Code=7 "The operation couldn’t be completed. (com.apple.accounts error 7.)", com.facebook.sdk:ErrorSessionKey=<FBSession: 0x175227e0, state: FBSessionStateClosedLoginFailed, loginHandler: 0x0, appID: 638916992864352, urlSchemeSuffix: , tokenCachingStrategy:<PFFacebookTokenCachingStrategy: 0x175a9900>, expirationDate: (null), refreshDate: (null), attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>}
I am logout from iPhone's Settings->Facebook then its working fine.
I have done research on it, but not getting solutions.
Can anyone help to solve my issue ?
Thanks,
Try with below code..You need to give permissions in the code as in below code..
-(IBAction)facebookButtonAction:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
self.accountStore = [[ACAccountStore alloc] init];
// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray * permissions = [NSArray arrayWithObjects:#"email",#"user_location",#"user_birthday", nil];
NSDictionary * dict=[NSDictionary dictionaryWithObjectsAndKeys:#“xxxxxxxxxxxxxxx,ACFacebookAppIdKey,permissions,ACFacebookPermissionsKey,ACFacebookAudienceEveryone,ACFacebookAudienceKey, nil];
[self.accountStore requestAccessToAccountsWithType:accountType options:dict completion:^(BOOL granted, NSError *error) {
NSLog(#"-------------error =%#--------- check grant bol %d",error,granted);
if(granted ) {
NSArray *accountsArray = [self.accountStore accountsWithAccountType:accountType];
if ([accountsArray count] > 0)
{
ACAccount *fbAccount = [accountsArray objectAtIndex:0];
NSDictionary *tempDict = [[NSMutableDictionary alloc] initWithDictionary:[fbAccount dictionaryWithValuesForKeys:[NSArray arrayWithObject:#"properties"]]];
NSString *facebookname;
facebookname=#"Name not found";
facebookname = [[tempDict objectForKey:#"properties"] objectForKey:#"ACPropertyFullName"];
if ([facebookname isKindOfClass:[NSNull class]] || facebookname==NULL || [facebookname isEqualToString:#""] || [facebookname isEqualToString:#"(null)"])
{
facebookname = [[tempDict objectForKey:#"properties"] objectForKey:#"fullname"];
}
//if (SYSTEM_VERSION_LESS_THAN(#"7.0"))
{
}
NSString *facebookID = [NSString stringWithFormat:#"%#", [[fbAccount valueForKey:#"properties"] valueForKey:#"uid"]] ;
NSString *pictureURL=[NSString stringWithFormat:#"https://graph.facebook.com/%#/picture?type=large&return_ssl_resources=1",facebookID];
NSLog(#" check the properties %#",tempDict);
NSLog(#" name nemae %#",facebookname);
NSLog(#" facebookID %#",facebookID);
NSLog(#" image https://graph.facebook.com/%#/picture?type=large&return_ssl_resources=1",facebookID);
if ([facebookname isKindOfClass:[NSNull class]] || facebookname==NULL || [facebookname isEqualToString:#""] || [facebookname isEqualToString:#"(null)"])
{
UIAlertView *somethingerr=[[UIAlertView alloc]initWithTitle:#“App Name” message:#"Something went wrong with facebook login. Please send your console report to the developers." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[somethingerr show
];
[self hidespinner];
return;
}
}
else{
UIAlertView *alerts=[[UIAlertView alloc]initWithTitle:#"No facebok account" message:#"Please add or create an account in \"settings \" " delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alerts show];
[self performSelector:#selector(hidespinner) withObject:nil afterDelay:0.1] ;
}
}
else{
switch ([error code])
{
case 0:
[self showErrorAlertWithMessage:#"Unknown error occured, try again later!"];
break;
case 1:
[self showErrorAlertWithMessage:#"Unknown error occured, try again later!"];
break;
case 3:
[self showErrorAlertWithMessage:#"Authentication failed, try again later!"];
break;
case 6:
[self showErrorAlertWithMessage:#"Facebook account does not exists. Please create it in Settings and come back!"];
break;
case 7:
[self showErrorAlertWithMessage:#"Permission request failed. You won't be able to share information to Facebook"];
break;
default:
[self performSelector:#selector(hidespinner) withObject:Nil afterDelay:0.1];
break;
}
}
}];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"No Facebook Accounts" message:#"There are no Facebook accounts configured. You can add or create a Facebook account in Settings." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[self performSelector:#selector(hidespinner) withObject:nil afterDelay:0.1] ;
}
}
Hope it helps you....!
I am new in iOS development and try to connect my iPhone device with the ejabberd server.I follow Xmpp.org document.And also I follow this "http://code.tutsplus.com/tutorials/building-a-jabber-client-for-ios-interface-setup--mobile-7188" document thoroughly.This is a great tutorial.This help me a lot a to setup a ejabberd server in my mac and able to connect to two different application(iMessage and Adium) through ejabberd server but I am facing some problem when I started iPhone application.
First I got XMPP importing error.but I solve it, after that app crash when I use [XMPPStream addDelegate: self delegateQueue:dispatch_get_main_queue() ] method.That time Compiler says "unrecognized selector sent".so I change it to [XMPPStream addDelegate:self ].Error removed.
And at last I got alert message which told me"Can't connect to server",and finally unable to connect to the server.
I want to test client-server connection locally,so I changed server address with my Mac Ip.but still unable to connect.
please help me....If possible please suggest me how to proceed further & any other document on XMPP.
Thanks a lot.
I call this connect function when application start.
- (BOOL)connect {
[self setupStream];
NSString *jabberID = [[NSUserDefaults standardUserDefaults]stringForKey:#"userID"];
NSString *myPassword =[[NSUserDefaults standardUserDefaults] stringForKey:#"userPassword"];
if (![xmppStream isDisconnected]) {
return YES;
}
if (jabberID == nil || myPassword == nil) {
return NO;
}
[xmppStream setMyJID:[XMPPJID jidWithString:jabberID]];
password = myPassword;
NSError *error = nil;
if (![xmppStream connect:&error]){
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error" message:[NSString stringWithFormat:#"Can't connect to server %#", [error localizedDescription]] delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alertView show];
[alertView release];
return NO;
}
return YES;
}
- (void)setupStream {
xmppStream = [[[XMPPStream alloc] init] autorelease];
[xmppStream addDelegate:self];
//[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
}
- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence {
NSString *presenceType = [presence type]; // online/offline
NSString *myUsername = [[sender myJID] user];
NSString *presenceFromUser = [[presence from] user];
if (![presenceFromUser isEqualToString:myUsername]) {
if ([presenceType isEqualToString:#"available"]) {
[_chatDelegate newBuddyOnline:[NSString stringWithFormat:#"%##%#", presenceFromUser, #"MYSERVER"]];
} else if ([presenceType isEqualToString:#"unavailable"]) {
[_chatDelegate buddyWentOffline:[NSString stringWithFormat:#"%##%#", presenceFromUser, #"MYSERVER"]];
}
}
}
in the connect method try using these two lines also, if u are using ejabberd as mentioned in the tutorial
xmppStream.hostName = #"localhost";
xmppStream.hostPort=5222;
i was following the same tutorial and it worked for me after adding these lines..put breakpoints in the
- (void)xmppStreamDidConnect:(XMPPStream *)sender
delegate method to check if its connecting
I am using the default classes provided by app to do my networking tasks in my app.
At some point, some of my requests time out (regardless of the reason for the timeout)
I would like to retry some of these requests
I have subclassed the NSURLConnection class and added some parameters to it.
However, in the method "connection:didFailWithError:"
con.retries seems to always be 1, never incremented. Why ?
- (void)connection:(NSURLConnection*) connection didFailWithError:(NSError *)error
{
[[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
NSLog(#"%#",[NSString stringWithFormat:#"Did recieve error: %#", [error description]]);
NSLog(#"%#",[NSString stringWithFormat:#"%#", [[error userInfo]description]]);
WBURLConnection *con = (WBURLConnection *)connection;
if([con shouldRetryRequest:error]){
con.retries ++;
[con start];
}else{
[con cancel];
[con.data setLength:0];
if(!self.alert){
self.alert = [[UIAlertView alloc]initWithTitle:#"Alert" message:[error localizedDescription] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[self.alert show];
}else {
if(![self.alert isVisible]){
[self.alert show];
}
}
}
}
-(BOOL)shouldRetryRequest:(NSError *)error{
[self.retryCount appendString:[NSString stringWithFormat:#"%#:%ld",error,(long)self.retries]];
LogInfo(#"retries:%#",self.retryCount);
if([error code] == -1004){
return NO;
}
return self.retries<3;
}