Facebook integration using parse framework - iphone

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:^{}];
}

Related

Wcsession session expired and error 7007

I am new in WatchKit and I am working on one of my app, but I am facing one problem regarding connection with Apple watch.
my source code is below:
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ //create a session using wcsession
if ([WCSession isSupported]) {
[[WCSession defaultSession] setDelegate:self];
[[WCSession defaultSession] activateSession];
}
return YES;
}
Send message action in my viewcontroller:
[[WCSession defaultSession] sendMessage:dict replyHandler:^(NSDictionary *replyHandler)
{
NSLog(#"Replay %#",replyHandler);
}
errorHandler:^(NSError *error) {
NSLog(#"Error %#",error);
}];
Also I activate the wcsession at watch side in complication controller
]if ([WCSession isSupported]) {
[[WCSession defaultSession] setDelegate:self];
[[WCSession defaultSession] activateSession];
}
and
-(void)session:(nonnull WCSession *)session
didReceiveMessage:(nonnull NSDictionary<NSString *,id> *)message
replyHandler:(nonnull void (^)(NSDictionary<NSString *,id> * __nonnull))replyHandler {
[extensionDelgate InsertIntoTideMaster:message];
[self requestedUpdateDidBegin];
dispatch_async(dispatch_get_main_queue(), ^{
});
}
This works first time when I am launching the app, but after that I got 7007 code error ... can you tell me what is missing here?
Thanks in advance.

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

How to redirect on app after successfull facebook login in iOS5

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.

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.

Push Notifications on iPhone App

I have successfully implemented push notifications to my app. The next step is, if the user receives a notification about this certain document, he/ she clicks it and it brings them to this document.
At the moment, I can receive the notification, but it only brings me to the app.
How can I do this?
Thanks.
I am not clear with your question. But you should handle push notifications in the following methods,
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//Handle here
}
and
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *tmpDic = [launchOptions objectForKey:#"UIApplicationLaunchOptionsRemoteNotificationKey"];
if (tmpDic != nil) {
//Handle here also
}
}