How to redirect on app after successfull facebook login in iOS5 - iphone

There is a facebook button in my app in login screen ,when user click on this button facebook login page open in browse and after successful login application redirect and display next page . Please hep mw with example .
IOS version : 5.0
ARC project
Thank You

by the way you guys can visit my reply here Native iOS Facebook SSO won't return to app
In my application i had to implement facebook and googleplus both and finally I made it successfully. I dont think facebook developer app portal needs any edit rather than getting appid. I made three apps with facebook login, one of them does not have iOS Native App setting in facebook developer app but that app's login part is also running well.

in your you AppDelegate modify the method
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
NSString *urlString = [url absoluteString];
if ([urlString hasPrefix:#"fb://xxxxxxxxxxxx"]) {
[FBSession.activeSession handleOpenURL:url];
returnValue = YES;
}
return returnValue;
}
xxx will be your facebookappid
But keep in mind that this is not triggered in IOS 6.In ios 6 the following method will be triggered.
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [FBSession.activeSession handleOpenURL:url];
}
If the state of your session changes due to login or disconnect FBsession calls the following method and you should handle your cases.
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState)state
error:(NSError *)error {
switch (state) {
case FBSessionStateOpen: {
//update permissionsArrat
[self retrieveUSerPermissions];
if (!needstoReopenOldSession) {
//First User information
[self getUserInformation:nil];
}
NSNotification *authorizationNotification = [NSNotification notificationWithName:facebookAuthorizationNotification object:nil];
[[NSNotificationCenter defaultCenter] postNotification:authorizationNotification];
}
case FBSessionStateClosed: {
break;
}
case FBSessionStateClosedLoginFailed: {
[FBSession.activeSession closeAndClearTokenInformation];
break;
}
default:
break;
}
if (error) {
NSNotification *authorizationNotification = [NSNotification notificationWithName:faceBookErrorOccuredNotification object:nil];
[[NSNotificationCenter defaultCenter] postNotification:authorizationNotification];
}
}

Use this official tutorial and you will be OK. See the 2-d point for your problem as well.

Related

Parse.com Facebook Login stays on "Loading" iOS

I'm using Parse, with the LogInViewController. I added Facebook on the logIn View.
When someone wants to connect with Facebook, it opens the browser, the user accepts the application and then he returns to the app. But when he returns on the app, he stays on "loading" and nothing happens.
However if the user restart the app, it works.
Only when it's the first connexion for the user I have this problem.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (![PFUser currentUser]) {
// Customize the Log In View Controller
PFLogInViewController *logInViewController = [[PFLogInViewController alloc] init];
[logInViewController setDelegate:self];
[logInViewController setFacebookPermissions:[NSArray arrayWithObjects:#"friends_about_me", nil]];
[logInViewController setFields: PFLogInFieldsFacebook | PFLogInFieldsDismissButton];
// Present Log In View Controller
[self presentViewController:logInViewController animated:YES completion:NULL];
}
}
I think the problem isn't in my code because I use the default code of Parse but I'm not sure.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
withSession:[PFFacebookUtils session]];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
[FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];
}
- (void)applicationWillTerminate:(UIApplication *)application {
/*
Called when the application is about to terminate.
Save data if appropriate.
See also applicationDidEnterBackground:.
*/
[[PFFacebookUtils session] close];
}

Facebook integration using parse framework

I done Facebook integration using parse framework with my application so how can i add logout button as well as permission to the user below mentioned image is my application screen-short as well how can i obtain okay button pressed event in my code..?
Login
In your app delegate, these lines should be present:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Parse setApplicationId:#"YOUR_APPLICATION_ID"
clientKey:#"YOUR_CLIENT_KEY"];
[PFFacebookUtils initializeWithApplicationId:#"YOUR_FB_APP_ID"];
// Override point for customization after application launch.
return YES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [PFFacebookUtils handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [PFFacebookUtils handleOpenURL:url];
}
This will ensure that parse is initialized and connected with your facebook app on startup. The two methods at the bottom are what enables your app to launch the screen to sign in to facebook and request permissions. In order to actually present that screen to the user, all that's necessary is a button that calls a method similar to this one:
-(IBAction)facebookLoginButtonPressed:(id)sender {
[self loginWithFacebook];
}
-(void)loginWithFacebook {
NSArray *permissionsArray = #[#"publish_actions", #"email", #"user_location"];
// Login PFUser using Facebook
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
if (!user) {
if (!error) {
NSLog(#"Uh oh. The user cancelled the Facebook login.");
} else {
NSLog(#"Uh oh. An error occurred: %#", error);
}
} else {
[self performSegueWithIdentifier:#"loginToFeed" sender:self];
}
}];
}
You shouldn't need an event callback for the ok, when the [PFFacebookUtils logInWithPermissions:block:] comes back, it will perform the block that you provide, enabling you to segue to different ViewControllers or show different features.
Log Out
Add a button to whatever view you want to have control logging out. Then add an IBAction method for that button:
-(IBAction)logOutButtonPressed:(id)sender {
[PFUser logOut];
NSLog(#"User logged out!");
[self dismissViewControllerAnimated:YES completion:^{}];
}

How do I respond to successful login with Dropbox API on iOS?

It checks whether the user is logged into dropbox when my app is launched. If they are, it continues with code relating to dropbox. If not, it shows them a login screen using [[DBSession sharedSession] link];.
From the login screen comes this delegate, if authorization fails:
-(void)sessionDidReceiveAuthorizationFailure:(DBSession *)session userId:(NSString *)userId {
[[DBSession sharedSession] link];
}
But there doesn't seem to be something for when authorization succeeds. How do I deal with this scenario? I need to start running the necessary code once they're linked with dropbox.
You handle successful login from the Dropbox API in the
-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url function
-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if ([[DBSession sharedSession] handleOpenURL:url]) {
//Successfully Logged in to Dropbox
return YES;
}
return NO;
}
As part of applicationDidFinishLaunching you could initiate the dropbox api you could do the following.
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
DBSession* dbSession = [[[DBSession alloc] initWithAppKey:#"appKey" appSecret:#"appSecret" root:kDBRootAppFolder] autorelease];
dbSession.delegate = self;
[DBSession setSharedSession:dbSession];
[[NSNotificationCenter defaultCenter] postNotificationName:kSharedSessionAvailability object:[NSNumber numberWithBool:dbSession != nil ? YES : NO]];
});
But normally you simply get your session and use it later via the restClient.

In App Purchase sandbox not prompting for my login/pass

We're developing an app which (ofcourse) uses in app purchases (IAP).
I've done everything in the guide to enable iap and everything works fine, untill I want to make purchase.
Some of the code:
MainViewController.m
-(void)viewDidLoad {
if ([SKPaymentQueue canMakePayments]) {
MyStoreObserver *observer = [[MyStoreObserver alloc] init];
[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];
SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObjects: #"com.company.app.product1", #"com.company.app.product1", nil]];
request.delegate = self;
[request start];
}
};
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
for (SKProduct *prod in response.products) {
NSLog(#"%# (%#)", prod.localizedTitle, prod.price);
}
[request release];
};
-(IBAction)clickBuy:(UIButton *)__sender {
SKPayment *payment = [SKPayment paymentWithProductIdentifier:#"com.company.app.product1"];
[[SKPaymentQueue defaultQueue] addPayment:payment];
};
MyStoreObserver.m
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:
NSLog(#"SKPaymentTransactionStatePurchased");
break;
case SKPaymentTransactionStateFailed:
NSLog(#"SKPaymentTransactionStateFailed");
break;
case SKPaymentTransactionStateRestored:
NSLog(#"SKPaymentTransactionStateRestored");
break;
case SKPaymentTransactionStatePurchasing:
NSLog(#"SKPaymentTransactionStatePurchasing");
default:
break;
}
}
};
The productRequest: delegate method shows 2 products with their name / price. Like I entered in the iTunes connect site.
But once I click the 'buy' button, no dialog pops up or asks me for my credentials. Only "SKPaymentTransactionStatePurchasing" is logged.
And I:
- ... have logged out in the settings/store pane
- ... am using the right provisioning profiles
- ... am desperate
Anyone?
I encountered a similar problem, but mine was more of a boneheaded move on my part. I had 'refactored' the call to finishTransaction so that it was being called for every state in transactionState:
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:
// do stuff
break;
case SKPaymentTransactionStateFailed:
// do stuff
break;
case SKPaymentTransactionStateRestored:
// do stuff
break;
default:
break;
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
}
Turns out™, this will also call finishTransaction on SKPaymentTransactionStatePurchasing, which will cause a crash. Moving finishTransaction back into each case of the switch statement fixed that.
After Pulling my hair out in frustration with a similar problem (instead of not being asked for my credentials it was automatically filling in the email address without the option to change it even when logged out of the store in the settings app). I discovered that I had a failed transaction stuck in the queue from development builds on the same device, I had to clear all of the transactions in the queue on the device and then try to test again.
NSArray *transactions = [[SKPaymentQueue defaultQueue] transactions];
for(id transaction in transactions){
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
I hooked this code upto an IBOutlet and after being run once my in app purchases worked.
I also had been pulling my hair out a bit with this. Turns out a simple reboot of the test device got everything working fine.
An iPhone can be restricted from accessing the Apple App Store. For example, parents can restrict their children’s ability to purchase additional content.
Before placing transaction make sure, can you u buy or not?Check it like this -
-(IBAction)clickBuy:(UIButton *)__sender {
if ([SKPaymentQueue canMakePayments]) {
SKPayment *payment = [SKPayment paymentWithProductIdentifier:#"Product_id"];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
else {
//show appropriate message
}
}
Are you testing on iPhone/iPad Simulator 4.2 or something? That might be the problem. Testing on iPhone/iPad Simulator 5.0, or the device, will run storekit correctly.

iphone: Set badge on a tabbarItem when receiving a PUSH message, when the app is inactive

I have a application that uses PUSH. But I have one problem when the application is inactive/in the background.
When the PUSH messages come and the user clicks on Close, the badge is set on the application-icon.
But I also want to set a badge on a tabBarItem.
I have this code that saves the PUSH
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (application.applicationState == UIApplicationStateInactive) {
//Save the PUSH until the app is active.
newPush = [userInfo copy];
}
}
And in:
- (void)applicationDidBecomeActive:(UIApplication *)application
I have the following code:
//Check if there is new PUSH messages.
if (newPush!=nil) {
//There is a new PUSH!
NSInteger badge = [[[newPush objectForKey:#"aps"] objectForKey:#"badge"] intValue];
if (badge > 0) {
//Set badge-numbers to 'badge'
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge];
[[[[[self tabBarController] tabBar] items] objectAtIndex:3] setBadgeValue:[NSString stringWithFormat:#"%d",badge]];
}
else {
//Set badge-numbers to zero
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[[[[self tabBarController] tabBar] items] objectAtIndex:3] setBadgeValue:nil];
}
}
My code for handling the PUSH when the application is active works fine and the badges are set both on the application-icon and on the tabBarItem.
Someone know what's wrong?
Thanks in advance!
If the application is inactive, didReceiveRemoteNotification is not executed. The only way the notification data can reach your app in this case is if the user taps on the notification to open the app. Then, when the app is launched, you can get the notification data in application:didFinishLaunchingWithOptions: by using this code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
//Accept push notification when app is not open
if (remoteNotif) {
[self handleRemoteNotification:application userInfo:remoteNotif];
return YES;
}
return YES;
}