Sharekit Authorization For Twitter - iphone

I want to authorize a user for my iphone app using Twitter. I would like to use sharekit to do this for simplicity but I am missing something fundamental. My understanding is that the way you do this is as follows:
service=[[SHKTwitter alloc] init];
[service authorize];
What is not clear to me is how I get notified once the authorization process is complete. When I execute this code, a modal view controller pops up and the user grants access via twitter. Authorization is successfully made and the modal view controller is dismissed. What I don't see is any way for me to be notified once all this is complete? What am I missing?

You could check two methods in SHKOAuthSharer (if you use OAuth to authorize):
1. - tokenAuthorizeView: didFinishWithSuccess:
2. - tokenAuthorizeCancelledView:
They where called when authorizing view is closing. So you could put your own delegate callbacks here.
Or check this https://github.com/ideashower/ShareKit/issues/187

Related

How to redirect after login in iOS app

I am working on an app and would like to know how to automatically redirect someone to their profile page or a home page after they login into my app?
If relevant I am using the Parse UI to log in and sign up and coding in swift and using Xcode7
Any advice welcomed
PFLoginViewController has a delegate with calls that you can use to indicate when a user has successfully logged in. I believe it gets called when a user signs up as well, but I could be mistaken.
You can use those calls to signal a successful login/signup and then redirect to the appropriate view controller from there. If you want any more advice, you will need to be more specific with your question.
As far as I understand you want to redirect your user to specific view controller if user already logged in ? You can use below code in your app delegate file.
var currentUser = Parse.User.currentUser()
if currentUser != nil {
// Your redirect code
}

How to remain logged in until user decides to logout?

I am designing an app that it uses the web service like posting links and pictures. The first view controller checks the default username and password of the user and if it is correct, it allows the user to login to the home view controller but if its not correct it directs the user to the login view controller (if its the first time that the application is running it also directs the user to the login view controller).
I have different view controllers that is connecting to the home view controller. For example one of them is for posting pictures to the website, the other one is for posting links to the web and the other view controller is for changing the preferences of the users profile.
I am using RestKit API to POST on web and here is the code that I use for posting:
- (IBAction)addLinkPressed:(UIButton *)sender {
[RKClient clientWithBaseURLString:#"http://MyWebsite.com"];
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
self.linkField.text, #"url",
self.linkTitleField.text, #"title",
self.linkSummaryField.text, #"summary",
nil];
RKRequest *request = [[RKClient sharedClient] post:#"/send_link.php" params:params delegate:self];
[request setUserData:#"sendLink"];
}
For each view controller I put the following method in viewDidLoad in order to get authentication for posting :
- (void)autoLogin {
[RKClient clientWithBaseURLString:#"http://MyWebsite.com"];
[RKObjectManager sharedManager].client=[RKClient sharedClient];
RKParams *parameters = [RKParams params];
[parameters setValue:[[NSUserDefaults standardUserDefaults] objectForKey:#"defaultUsername"] forParam:#"username"];
[parameters setValue:[[NSUserDefaults standardUserDefaults] objectForKey:#"defaultPassword"] forParam:#"password"];
[[RKClient sharedClient] setAuthenticationType:RKRequestAuthenticationTypeHTTP];
RKRequest *request = [[RKClient sharedClient] post:#"/login.php" params:parameters delegate:self];
[request setUserData:#"login"];
}
Question: Is there any method to get authentication from the website for posting other than logging in for each view controller? the problem for logging in for each view controller is that some times logging process gives an error and does not allow the user to POST. I need a method that as soon as the user inputs the correct username and password, It remains logged in until the user logout by himself or delete the app.
I found this relative question but It was not that helpful or I did not understand the answers well. Any thoughts or ideas would be appreciated.
RestKit is designed to consume APIs. Usually APIs are stateless, meaning that there is no such thing as state between requests. On traditional websites state is achieved by transmitting cookies back and forth between client and server. Apparently RestKit does not handle cookies (which is good in my opinion). From the top of my head I can think of two solutions:
Apparently RestKit does not handle cookies automatically. Thus, you could get the cookie after the login and attach it to every subsequent request.
Better: use OAuth2, which is basically a token that the user receives when logging in. This token is then appended as a parameter to each request.
Both methods are basically the same. You have to send a token that identifies the user as logged in.
If I understand well your situation, you have many viewcontrollers that act separately and independently. Doing so you need as many logins as the number of viewcontrollers your app manages.
If this is your scenario, you can try to create a single class that does the login work and use your other viewcontrollers just to handle GUI.
This will be your architecture:
App other classes and viewcontrollers -> LOGINMANAGER -> viewcontroller 1 (pictures), viewcontroller 2 (links), viewcontroller 3 (preferences), viewcontroller 4 (whatever)...

Facebook Logout in iPhone Application

I have integrated the facebook in to my application, From the FB i will be getting the userid and the name of the user and passing it to my own service that will do the validation and allows the respective user to get in to the system. I have got the userid and username from the FB and passed it my service that will do the validation,it allows the user to enter in to app, but my problem is once i logged in , how can i log out from the FB ?
Please let me know your ideas.
Thanks
If you are using the new facebook sdk, then us
[facebook logout:delegate]
Being facebook your Facebook object,and delegate an FBSessionDelegate.
If all goes well your delegate will be called on -(void)fbDidLogout;
That depends on which library you use to connect to facebook.
But I guess that you have a FBSession class that has a logout method...
That logout method also calls deleteFacebookCookies that you could also directly call depending on your needs...
Hope that helps.
If you are using old facebook sdk,then use this code for logout.make FBSession class object and code like this. [FBSessionclassobject logout];
it will delete all FacebookCookies.

Logout using MGTwitterEngine?

How to logout using MGTwitterEngine API programmatically in iphone ?
You mean how do you log out from the current account in MGTwitterEngine?
Well, that's easy, simply send the -endUserSession-selector to the engine like this:
MGTwitterEngine *engine = [MGTwitterEngine twitterEngineWithDelegate:self];
// Login...
// Do stuff...
[engine endUserSession]; // <-- Logs out
To Logout of the Twitter from MGTwitterEngine you need to call its methods with some change. In the MGTwitterEngine.m, search for _clearCookies. This is currently set to NO, change it to YES. In your action method for logging out the current user, call [ _engine clearAccessToken].
Now run it, and voila, it works!

Facebook Connect on iPhone question

When you use facebook connect on the iPhone do you have to use the supplied login button and login screen built into the framework? The reason I ask is because I'm also using twitter and I would like to have the same user experience when they log in to user as they have when they log in to facebook. So I can either replicate the login screen facebook connect uses for twitter or just not use the facebook connect login screen all together.
Login button: no. Login screen: yes. I added FB Connect integration to my FriendFeed app for iPhone, Stir, and skipped the login button. Instead, a user can choose a "Share on Facebook" button on a UIActionSheet and the app either displays a login screen or automatically posts a link depending on whether the user is authenticated.
Here's a code snippet for you. If the session is successfully resumed, then a method on your FBSession object's delegate will be called.
if (![fbSession resume]) {
FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:fbSession] autorelease];
[dialog show];
}
- (void)session:(FBSession*)session didLogin:(FBUID)uid {
NSLog(#"Hooray, I'm logged in to Facebook!");
}
Apologies for being a little vague in my example above. To be honest, I find FBConnect to be a bit of a mystery and tried my best to implement it and get away from it as quickly as possible in my app. Let me know if you need more information and I'll put together a more-concrete answer.
Per the request below:
You can get an FBSession object with FBSession's +sessionForApplication:secret:delegate class method. You call -resume on the session object. If it returns YES, it'll immediately call your delegate's -session:didLogin: method, which is where you should put your FB-dependent actions. If it does not successfully -resume, then you need to create an FBLoginDialog, as seen in the code snippet above. Make sense? Let me know if you need more info