Parse.com Facebook Login stays on "Loading" iOS - facebook

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

Related

localNotification issues

I am sending a local notification once a process is finished and it acts just fine.
This is my code for didReceiveLocalNotification:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
CounterViewController *counterVC = [CounterViewController sharedInstance];
[counterVC notificationArrived];
}
But when the iPhone is locked those lines aren't called… What can I do to make them run in the background?
There are two method to receive local notification one is already you have implemented which is invoked while app is running & 2nd is in didFinishLaunchingWithOptions which is invoked while your app is running background you have add some code for receive local notification .....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
application.applicationIconBadgeNumber = 0;
// Handle launching from a notification
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSLog(#"Recieved Notification %#",localNotif);
}
return YES;
}

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.

network activity indicator is not shown on iPhone (iOS 5)

just to test it I enabled the activity indicator of the status bar as follows:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible: TRUE];
//...
}
I never disable the indicator so it should always be visible, but it isn't. It is visible in the iPhone Simulator but not on the device. Why?
Please not that the application is not active when a call is made to didFinishLaunchingWithOptions. You should move this to the viewDidLoad method instead. Thus the code should look like this:
- (void)viewDidLoad {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
// Some other code goes here...
[super viewDidLoad];
}
Or you could put this code anywhere else where the view has been loaded. Do not forget to stop it once the data has been loaded.

How to handle a custom URL in an already-open app?

I have an app based on the Utility template (i.e. Main and Flip view controllers). The Flip view allows selecting a certain item to be used on the main view. So far - works great.
Now I tried adding a custom URL. Something to the effect of: myapp://itemID=40 that will basically tell the main view: "no need to flip - you'll be dealing with item 40".
I registered the URL type scheme as "myapp" and added the following method to the app delegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if (!url) {
return NO;
}
NSString *urlString = [url absoluteString];
NSLog(#"URL received: %#", urlString);
NSString *itemID = [urlString stringByReplacingOccurrencesOfString:#"myapp://itemID=" withString:#""];
NSLog(#"Item received: %#", itemID);
[_mainViewController setStartupItem:itemID];
return YES;
}
As you can see, the itemID is set to a property called startupItem in the mainViewController.
I then added one line to the regular application method to verify that startupItem will be nil in case of no URL:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Make sure URL string is empty
[_mainViewController setStartupItem:nil];
// Override point for customization after application launch.
// Add the main view controller's view to the window and display.
self.window.rootViewController = self.mainViewController;
[self.window makeKeyAndVisible];
return YES;
}
And in MainViewController.m I added code to handle the item to the viewDidLoad event.
And here's my problem: this scheme works great if the app is started from a URL the first time. If it's already running, then we never reach viewDidLoad again and therefore don't handle that particular item, but go on as if none was passed.
My humble question is: which UIViewController should I put my handling code in? Or, am I approaching all this the wrong way? Should this be handled in my model?
As always, thanks in advance for your time!
Guy
I would take a look at the docs for UIApplicationDelegate protocol, specifically;
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
And this which is deprecated.
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
Well definitely not in a method that gets called only once while the application starts up! You need to refactor the item handling code in its own method, then call this method from viewDidLoad (once during startup) and handleOpenURL each time it gets called.