Quick blox chat not authenticating - ios

I am using quickblox in my app to do 1 to 1 chat.
The user is already login.
But when I try to login the chat, I get the following error.
2014-03-31 12:42:09.532 MyChat[2175:3803] QBChat/didNotAuthenticate, error: <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
2014-03-31 12:42:09.533 MyChat[2175:3803] -[QBContactList dealloc] ->
2014-03-31 12:42:09.533 MyChat[2175:3803] QBChat/didDisconnect, error: (null)
What am I doing wrong.
QBUUser *currentUser = [QBUUser user];
[QBChat instance].delegate = self;
[[QBChat instance] loginWithUser:currentUser];

It's not a right way,
currentUser instance is empty, you should set ID and password at least to login to Chat
For example
QBUUser *user = [QBUUser user];
user.ID = 979387;
user.password = #"userpass";
[[QBChat instance] loginWithUser:user];

Related

How to merge a user signed up by facebook with an exising user signed up with the same email

I am using parse in an iOS app and there are two ways of signup, either using email/password or Facebook login.
The problem happen when a user sign up using his email/password then logout and try to sign up using his Facebook account which have the same email.
I am using [PFFacebookUtils logInInBackgroundWithReadPermissions:block: to signup with Facebook which creates a new user object in the Users table in Parse
Now I have two records for the same user and I can not update the record that has the Facebook information with the user email because Parse will not allow duplicate emails
So what should be the best solution to solve this problem?
UPDATE
I have used #kRiZ solution to login using plain Facebook code then either create new user or link the user with the Facebook data
- (void)loginWithFacebookWithSuccessCallback:(APISuccessCallback)successCallback
andFailureCallback:(APIFailureCallback)failureCallback {
// Login PFUser using Facebook
NSArray *permissionsArray = #[#"public_profile", #"email"];
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions: permissionsArray handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
failureCallback(error);
} else {
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:#"me?fields=id,first_name,last_name,email,gender" parameters:nil];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id fbResult, NSError *error) {
if (!error) {
NSString *email = result[#"email"];
User *existingUser = [self getUserByEmail:email];
if (existingUser == nil) {
[self signUpNewUserWithEmail:email];
} else {
// Need to set the current user to existingUser
}
[self linkCurrentWithAccessToken:result.token
successCallback(#{RESULT:RESULT_OK});
} else {
failureCallback(error);
}
}];
}
}];
}
Now the problem is to assign the [PFUser currentUser] to the existing user in case it is already exists
You can try linking the new Facebook user to an existing user on Parse using the [PFFacebookUtils linkUserInBackground:*... methods.
if (![PFFacebookUtils isLinkedWithUser:user]) {
[PFFacebookUtils linkUserInBackground:user withReadPermissions:nil block:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSLog(#"Woohoo, user is linked with Facebook!");
}
}];
}
See Parse documentation on linking.
Login via Facebook (do not save user yet)
Query the user table for user having the same email as this new FB user
If found, link, else, save as new user.
UPDATE:
Linking method with FB access token:
[PFFacebookUtils linkUserInBackground:user
withAccessToken:accessToken
block:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSLog(#"Woohoo, the user is linked with Facebook!");
}
}];

QuickBlox : Error while trying to login into QBChat in iOS 9

I'm trying to login into QuickBlox Chat (QBChat) but couldn't login into iOS9 (running via XCode7 beta). It was working great in iOS 7 and 8. An error logs the following in debug console:
2015-07-06 17:56:47.464 MyApp[25156:251907] xmppStreamDidConnect
2015-07-06 17:56:47.464 MyApp[25156:251907] -[QBChat xmppStreamDidConnect:] -> Trying TLS...
2015-07-06 17:56:47.910 MyApp[25156:251916] -[QBChat xmppStreamDidDisconnect:withError:] -> error:
Error Domain=kCFStreamErrorDomainSSL Code=-9850 "The operation couldn’t be completed.
(kCFStreamErrorDomainSSL error -9850.)" UserInfo=0x7f9dd962e430
{NSLocalizedRecoverySuggestion=Error code definition can be found in Apple's
SecureTransport.h}
Today, I've updated my QuickBlox iOS SDK from 2.2 to 2.3. So I've setup everything as per they want.
Note, I'm able to create session but couldn't able to login into QBChat.
Here's my sample code:
QBSessionParameters *parameters = [QBSessionParameters new];
parameters.userLogin = ...;
parameters.userPassword = ...;
[QBRequest createSessionWithExtendedParameters:parameters successBlock:^(QBResponse *response, QBASession *session) {
DLog(#"Success");
QBUUser *user = [QBUUser user];
user.ID = ...;
user.password = ...;
[[QBChat instance] addDelegate:self];
[[QBChat instance] setAutoReconnectEnabled:YES];
BOOL requestQBChatLogin = [[QBChat instance] loginWithUser:user];
if(!requestQBChatLogin) {
//This will never prints in logs
DLog(#"Something went wrong while sending request for QBChatLogin.");
}
} errorBlock:^(QBResponse *response) {
DLog(#"Error: %#", response.error);
}];
-(void) chatDidLogin{
//This will never call
DLog(#"You have successfully signed in to QuickBlox Chat!");
}
- (void) chatDidNotLogin {
//This will never call
DLog(#"You have not signed in to QuickBlox Chat!");
}
Please make sure that – I've added proper values for userName or ID or password as and when require.
Please try again, this problem has been fixed. It works on iOS 9 beta 4+

Parse: Cannot sign up a user created automatically

I'm using Parse 1.7.1 for iOS and I am trying to sign up a user. I chose to let the user interact with the app before I force the sign up / login process. The problem is that as soon as I call signUp the session object disappears from the server and causes any subsequent calls to return error 209.
Here's some code:
AppDelegate:
[PFUser enableAutomaticUser];
[[PFUser currentUser] incrementKey:#"runCount"];
[[PFUser currentUser] saveInBackground];
When I check the Parse Core console I can see a valid User & Session.
MyController:
PFUser *user = [PFUser currentUser];
if (! user) {
user = [PFUser user];
}
user.email = #"my#email.com";
user.password = #"somepassword";
user.username = #"whatever";
// I also tried Save instead of signUpInBackground... same result
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSLog(#"Success signing up");
}
else {
NSLog(#"Error %#", [error localizedDescription]);
}
}];
When I check the console there is an updated user but there is no Session anymore.
Any other API call
[Error]: invalid session token (Code: 209, Version: 1.7.1)
Despite the fact that the callback returns success as soon as I try to interact with the Parse API I get a 209, invalid session token. This is fair enough, since the session object is not present in the console.
Does anyone know what I am doing wrong?
Note: this a brand new app (not affected by the change made by Parse on the 25th of March)/.
I have raised this as a bug with Facebook and they are fixing it in 1.7.3
Here's the conversation I had with them.
Create button with selector -signUpSelector. And need implement this code:
-(void)signUpSelector
[PFUser becomeInBackground:#"session-token-here" block:^(PFUser *user, NSError *error) {
PFUser *newUser = nil;
if (error) {
newUser = [PFUser user];
} else {
newUser = user;
}
user.email = #"my#email.com";
user.password = #"somepassword";
user.username = #"whatever";
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSLog(#"Success signing up");
}
else {
NSLog(#"Error %#", [error localizedDescription]);
}
}];
}];

Unable to get Email Id Of logged person in Facebook ios SDK

I am working on a Facebook IOS app to fetch user data(Public Profile,Email) from the Facebook.After implementing login process i am able to fetch first name,last name and url for profile picture of the User but the email i am getting is null. i have passed the permission for getting public Profile and Emial.but i am not getting Email Of the person.
I am using facebook SDK for ios V4.0.1
Here is my code
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"me"
parameters:#{#"fields": #"first_name, last_name, picture, email"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSString *firstName = [NSString stringWithFormat:#"%#",[result objectForKey:#"first_name"]];
NSString *lastName = [NSString stringWithFormat:#"%#",[result objectForKey:#"last_name"]];
NSString *email = [NSString stringWithFormat:#"%#",[result objectForKey:#"email"]];
NSString *picurl = [NSString stringWithFormat:#"%#",[result objectForKey:#"picture"]];
NSLog(#"email is %#", [result objectForKey:#"email"]);
NSLog(#"picture is %#", [result objectForKey:#"picture"]);
}
else{
NSLog(#"%#", [error localizedDescription]);
}
}];
I am getting the Following Output:
email is (null)
picture is {
data = {
"is_silhouette" = 0;
url = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/v/t1.0-1/p50x50 **************_************_n.jpg?oh=ed5fd60c770cb5f34424b3fcfb4ca174&oe=559F472D&__gda__=1437970763_989a264cf7ec16f5d51b0a58b7e7f609";
};
}
why i am not getting Email Address of the User
While logging. You must ask user permission for email or else you would get email as (null).
Would not fetch Email ID
FBSDKLoginButton *loginView = [[FBSDKLoginButton alloc] init];
loginView.readPermissions = #[#"public_profile"];
IF you login with above permission then you would not be able to get email id it will always be return (null).
Would fetch Email ID with Public profile
FBSDKLoginButton *loginView = [[FBSDKLoginButton alloc] init];
loginView.readPermissions = #[#"email"];
Our app gets public_profile permission automatically upon any successful login but it does not get email.
Same goes for custom login as well.
Refer to :https://developers.facebook.com/docs/facebook-login/ios/v2.3#login-apicalls
If you were to assume the logic that setting FBSDKLoginButton.readPermissions to ["public_profile","email"] would be the way to express that you want the Facebook user's "public_profile" and their "email" address you will be sorely mistaken. Very confusing in my opinion, the following gives you both the Facebook user's public profile and their email address:
FBSDKLoginButton.readPermissions = ["email"]

QBUser from PFUser

I have an existing ios app that was created using the Parse PFLoginController for Facebook/Twitter login. I want to add a new tab for video chat and was wondering if there is a simple way to create a QBUser out of an existing PFUser to use for chat.
Thanks,
EE
PFUser class reference https://www.parse.com/docs/ios/api/Classes/PFUser.html
QBUser class reference http://sdk.quickblox.com/ios/Classes/QBUUser.html
PFUser *pfUser = [PFUser currentUser];
QBUUser *user = [QBUUser user];
user.ID = pfUser.objectId;
user.login = pfUser.username;
user.email = pfUser.email;
user.password = pfUser.password;
If you use Facebook login - it's also easy to do it - you just need Facebook access token.
You can get QBUser from Facebook access token
[QBUsers logInWithSocialProvider:#"facebook" accessToken:#"AAAGmLYiu1lcBADxROiXg4okE80FQO1dJHglsbNT3amxmABnmBmhN6ACbgDqNC3H4Y9GmZAdoSfPUkI9O7ZBJvKQCewNZAp3SoxKCNIMwQZDZD3" accessTokenSecret:nil delegate:self];
- (void)completedWithResult:(Result *)result{
if(result.success && [result isKindOfClass:QBUUserLogInResult.class]){
QBUUserLogInResult *res = (QBUUserLogInResult *)result;
QBUUser *user = res.user;
// Login to chat to use VideoChat features
QBUUser *currentUser = [QBUUser user];
currentUser.ID = user.ID;
currentUser.password = [QBBaseModule sharedModule].token; //Facebook/Twitter authentication: use session token as password
// set Chat delegate
[QBChat instance].delegate = self;
// login to Chat
[[QBChat instance] loginWithUser:currentUser];
}
}
I've never heard of QB until now. It looks like a cool service, so I'll have to check it out. That said, since I've never messed with it, this is all theoretical.
I've got a couple apps that I've built a generic chat implementation using Parse, so it would be neat to transition to a true messaging based platform. The way I would do it, instead of having people sign up for two different accounts, if you still need the Parse back-end for data persistence, is to have your Parse users just be anonymous. When creating PFObject data for Parse, just create a field for the QBUser's ID number. Then if you need to find info pertaining to that anonymous user, set your PFQuery to search for the ID field for the given QBUser.
It's not completely thought through but I could see it working out.

Resources