how to disable facebook login dialog - objective-c

I'm new in facebook SDK and iOS deverlop, my app have a problem when user login facebook, when I use a same account fb to login, my app always show this login dialog:
I want my app only show that dialog when a fb account login in the first time, but I don't know how to do it, here is my code:
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error {
switch (state) {
case FBSessionStateOpen:
if (!error) {
mainViewController *mainView = [self.storyboard instantiateViewControllerWithIdentifier:#"mainView"];
[self.navigationController pushViewController:mainView animated:YES];
// We have a valid session
NSLog(#"User session found");
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
[[NSNotificationCenter defaultCenter]
postNotificationName:FBSessionStateChangedNotification
object:session];
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"email",
#"user_likes",
nil];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
- (IBAction)authLogin:(id)sender {
[self openSessionWithAllowLoginUI:YES];
}
I use fb sdk 3.2 and ios simulator 6.1

I think this will help you,have a look :
Facebook developer section

Related

MFMessageComposeViewController - Getting stuck after sending SMS in ios7

After sending SMS from my phone(it's working properly) in my project using the MFMessageComposeViewController I can't get back to the app or press cancel. Instead I'm stuck in Apple SMS interface and I can't do anything else then to restart the app. Do I miss something in didFinishWithResult or could it be something else? Thanks
- (IBAction)sendSMS:(id)sender {
MFMessageComposeViewController *controller =
[[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
NSString *str= #"Hi";
controller.body = str;
controller.recipients = [NSArray arrayWithObjects:
#"", nil];
controller.delegate = self;
[self dismissViewControllerAnimated:YES
completion:nil];
[self presentViewController:controller animated:YES completion:nil];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult) result
{
switch (result) {
case MessageComposeResultCancelled:
break;
case MessageComposeResultFailed:
{
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Failed to send SMS!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warningAlert show];
break;
}
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}

QuickBlox : GCDAsyncSocketErrorDomain error

I'm trying to Implement chat module in my app. I am successfully done with Login and Register process from Simple Chat Demo into my app. It also returns user array of offline and online users.
Now after successfully log in I am getting below log :-
error:
2012-12-07 14:50:07.056 App[5324:790b] QBChatService/xmppStreamDidConnect
2012-12-07 14:50:08.285 App[5324:790f] QBChatService/xmppStreamDidAuthenticate
2012-12-07 14:51:08.291 App[5324:711f] QBChatService/xmppStreamDidDisconnect, error=Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo=0xb982330 {NSLocalizedDescription=Socket closed by remote peer}
And I'm not able to receive chat messages into my app.
Any suggestions ?
Edit :-
In my app, when login is done I am sending the login request to QuickBlox API
if(loginDone)
{
NSString *userName = [_textUsername.text stringByReplacingOccurrencesOfString:#"#" withString:#"_"];
NSString *userPass = [_textPassword.text stringByReplacingOccurrencesOfString:#"#" withString:#"_"];
// Authenticate user
[QBUsers logInWithUserLogin:userName password:userPass delegate:self context:userPass];
}
#pragma mark -
#pragma mark QBActionStatusDelegate
// QuickBlox API queries delegate
-(void)completedWithResult:(Result *)result context:(void *)contextInfo
{
// QuickBlox User authentication result
if([result isKindOfClass:[QBUUserLogInResult class]])
{
// Success result
if(result.success)
{
QBUUserLogInResult *res = (QBUUserLogInResult *)result;
// save current user
[[DataManager shared] setCurrentUser: res.user];
NSLog(#"%#",res.user);
[[[DataManager shared] currentUser] setPassword:(NSString *)contextInfo];
NSLog(#"%#",res.user);
// Login to Chat
[QBChat instance].delegate = self;
[[QBChat instance] loginWithUser:[[DataManager shared] currentUser]];
// Register as subscriber for Push Notifications
[QBMessages TRegisterSubscriptionWithDelegate:nil];
// send request for getting user's filelist
PagedRequest *pagedRequest = [[PagedRequest alloc] init];
[pagedRequest setPerPage:10];
[QBContent blobsWithPagedRequest:pagedRequest delegate:self];
[pagedRequest release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Errors"
message:[result.errors description]
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles: nil];
alert.tag = 1;
//[alert show];
[alert release];
[HUD hide:YES];
[self AfterLoginController];
}
}
}
-(void)completedWithResult:(Result *)result
{
if([result isKindOfClass:[QBUUserLogInResult class]]) // QuickBlox User authentication result
{
// Success result
if(result.success)
{
// If we are authenticating through Twitter/Facebook - we use token as user's password for Chat module
[self completedWithResult:result context:[BaseService sharedService].token];
}
}
else if ([result isKindOfClass:[QBCBlobPagedResult class]])
{
// Success result
if(result.success){
QBCBlobPagedResult *res = (QBCBlobPagedResult *)result;
// Save user's filelist
[DataManager shared].fileList = [[res.blobs mutableCopy] autorelease];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[app startsendPresenceTimer];
[HUD hide:YES];
[self AfterLoginController];
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Errors"
message:[result.errors description]
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles: nil];
alert.tag = 1;
//[alert show];
[alert release];
[HUD hide:YES];
[self AfterLoginController];
}
}
Now in AppDelegate :-
- (void) startsendPresenceTimer
{
[QBChat instance].delegate = self;
// send presence
if(self.sendPresenceTimer == nil)
{
self.sendPresenceTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:#selector(sendPresence) userInfo:nil
repeats:YES];
}
if (self.requesAllUsersTimer == nil)
{
self.requesAllUsersTimer= [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:#selector(updateUsers) userInfo:nil repeats:YES];
}
[self.requesAllUsersTimer fire];
}
// send presence
- (void)sendPresence{
// presence in QuickBlox Chat
[[QBChat instance] sendPresence];
// presence in QuickBlox
[QBUsers userWithExternalID:1 delegate:nil];
}
- (void)updateUsers
{
// Retrieve all users
PagedRequest* request = [[PagedRequest alloc] init];
request.perPage = 100; // 100 users
[QBUsers usersWithPagedRequest:request delegate:self];
[request release];
}
Do you send presence periodically? It need because Chat server must knows is you online or offline.
Look at QuickBlox Chat setup guide, lines
Keep in mind that QuickBlox it's simple XMPP chat, ...
Just write single line
[NSTimer scheduledTimerWithTimeInterval:30 target:[QBChat instance] selector:#selector(sendPresence) userInfo:nil repeats:YES];
Application will send presence every 30 seconds

Facebook SDK 3.1 for iOS login issues

I have used Facebook sdk 3.1 in my ios app for sharing link on friends wall. I try to open a new session in the applicationDidFinishLaunching method as below
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
myAppDelegate = self;
AudioViewController *viewController = [[AudioViewController alloc] init];
self.navController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.navController setNavigationBarHidden:YES];
viewController = nil;
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
if (![self openSessionWithAllowLoginUI:NO]) {
// No? Display the login page.
[self performSelector:#selector(login) withObject:nil afterDelay:0.5];
}
return YES;
}
- (void)login{
[self openSessionWithAllowLoginUI:YES];
}
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
return [FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState)state
error:(NSError *)error{
switch (state) {
case FBSessionStateOpen: {
DLOG(#"session open");
}
break;
case FBSessionStateClosed: {
DLOG(#"session closed");
[FBSession.activeSession closeAndClearTokenInformation];
}
break;
case FBSessionStateClosedLoginFailed: {
DLOG(#"session Failed");
}
break;
default:
break;
}
[[NSNotificationCenter defaultCenter] postNotificationName:WVSessionStateChangedNotification
object:session];
if (error) {
DLOG(#"error = %#",error);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:#"Error: %#",
[AppDelegate FBErrorCodeDescription:error.code]]
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
With some of the Facebook accounts it returns error "The operation could not be completed" com.facebook.sdk error 2. and so further cannot post on Facebook.
Am I doing something wrong here ?Any help would be appreciated.!
I had same issue, and i have solved it by calling openSessionWithAllowLoginUI:TRUE via NSTimer.
if (![self openSessionWithAllowLoginUI:NO]) {
// No? Display the login page.
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(login) userInfo:nil repeats:NO];
}
The reason is, we can't get FB session on different threads, either we use main thread or another(background) thread. In your code, when you check session availability, you use main thread and for login, you use different thread via performSelector function.
Hope, it will help you.
thanks

App crashing after touching email text MFMailComposeViewController

I'm implementMFMailComposeViewController in my demp app. However, for some reasons, my app crashes after I touch to add texts in the email text field. But sending WITHOUT adding any text works fine.
My Xcode is not showing too much. Here is what I'm getting:
I'm setting an initial text already in the email text field. Maybe the issue is here? request any code and I'll be happy to include it.
UPDATE:
Here 2 methods where the first method openMail fires up when touching the UIButton
- (IBAction)openMail:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#"Feedback from Demo App user"];
NSArray *toRecipients = [NSArray arrayWithObjects:#"myEMAIL#hotmail.com", #"myEMAIL2#gmail.com", nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody = #"Happy to hear your feedback!";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[mailer release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(#"Mail cancelled: you cancelled the operation and no email message was queued.");
break;
case MFMailComposeResultSaved:
NSLog(#"Mail saved: you saved the email message in the drafts folder.");
break;
case MFMailComposeResultSent:
NSLog(#"Mail send: the email message is queued in the outbox. It is ready to send.");
break;
case MFMailComposeResultFailed:
NSLog(#"Mail failed: the email message was not saved or queued, possibly due to an error.");
break;
default:
NSLog(#"Mail not sent.");
break;
}
// Remove the mail view
[self dismissModalViewControllerAnimated:YES];
}
Probably you're using ARC, and you're not have strong pointer to your MFMailComposeViewControllerand after display, ARC is releasing it.
use
#property (nonatomic,stron) MFMailComposeViewController *mail;
and when you're initialize MFMailComposeViewController:
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
self.mail = mailer;
Do you still have this line in your code:
[mailer release];
If so that is the problem. If not, then PLEASE update our code sample so its exactly what you are using now.

Not receiving email sent using MessageUI framework

I am using the MessageUI framework to send an email but I never receive that email when sent.
I am importing #import <MessageUI/MessageUI.h>
and then I have the following code
- (void)emailFile
{
if(![MFMailComposeViewController canSendMail]) {
UIAlertView *cantSend = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Device not configured to send email" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[cantSend show];
[cantSend release];
} else {
MFMailComposeViewController *mailView = [[[MFMailComposeViewController alloc] init] autorelease];
mailView.mailComposeDelegate = self;
[mailView setToRecipients:[NSArray arrayWithObject:#"matthew.inman#cdl.co.uk"]];
[mailView setSubject:#"Test"];
[mailView setMessageBody:#"This is a text message" isHTML:NO];
[self presentModalViewController:mailView animated:YES];
}
}
and
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
if(error) {
UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:#"Mail Error" message:[error localizedDescription] delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[errorView show];
[errorView release];
} else {
switch (result) {
case MFMailComposeResultSent:
NSLog(#"Sent Mail");
break;
case MFMailComposeResultSaved:
NSLog(#"Mail Saved");
break;
case MFMailComposeResultCancelled:
NSLog(#"Mail Cancelled");
break;
case MFMailComposeResultFailed:
NSLog(#"Mail Failed");
break;
default:
break;
}
}
[controller dismissModalViewControllerAnimated:YES];
}
I get the message "Sent Mail" in the console but I like I said I never receive the email that I am sending.
I have gone through the apple documentation and can't find anything that helps can anyone else help me please. I'm I doing something wrong?
Make sure you are testing on a device, email will not be sent via the simulator.