Login View in tabbed application - objective-c

How can I build a login view in a tabbed application? I'm new in ios development. I have read a lot through the internet but no one just posts the code I can understand. Any help is appreciated =).

here is a related post here: Adding login screen in front of Cocoa Touch Tab Bar Application for IOS
I prefer writing like this tho.
[window setRootController:tabBarCon];
if (notLogedIn) {
loginViewController = [[InitialScreenViewController alloc] init];
[tabBarCon.view addSubview:loginViewController.view];
}
[window makeKeyAndVisible];
return YES;
- (bool)notLoggedIn {
//check if there is any sessions exists in local storage
}
If your content relates to the user account, remember to implement a method to reload the the content after login.

Finally I did This to solve my question:
My rootViewController is my registration view, then I set a button with implements a custom segue:
-(IBAction)button {
NSLog(#"username: %#, password: %#, passwordrt: %#", username.text, password.text, passwordrt.text);
[self performSegueWithIdentifier:#"tabBar" sender:self];
}

Related

How do I post my own app with facebook

I have made an app and I want to create a UIButton that shares this app with facebook users.
I wrote the following code:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"My App Name"];
[controller addURL:[NSURL URLWithString:#"https://itunes.apple.com/il/app/fruit-ninja-free/id403858572?mt=8/"]];
[self presentViewController:controller animated:YES completion:Nil];
}
else {
}
I've used an example URL of the famous fruit ninja cause my app is not yet on the app store and doesn't have it's own URL.
The issue:
If the app is not yet on iTunes, I don't have an iTunes URL to share yet... So how do I share my app?
Help is much appreciated...
You should create stub for your app at iTunes Connect. After that you'll be able to get link to your application even before submission.

Proper usage windows

I am working on my first Cocoa Mac OS X program and wondering the best approach to showing the windows.
I have my AppController / MainMenu.xib as the main launch window but have the MainMenu.xib window unchecked for Visible At Launch. I do this because on application load I am checking to see if they are logged in. If not I want to display the Login.xib window instead of the MainMenu.xib. Once logged in, I would open the MainMenu.xib window and close the LoginController I have this in the - (void)applicationDidFinishLaunching:(NSNotification *)aNotification method.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSLog(#"app delegate");
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Defaults" ofType:#"plist"]]];
BOOL didAuth = NO;
GTMOAuth2Authentication *auth = [GTMClasses authForService];
if (auth) {
didAuth = [GTMOAuth2WindowController authorizeFromKeychainForName:kKeychainName authentication:auth];
}
if (didAuth) {
[[DataClass sharedInstance] setIsSignedIn:YES];
NSLog(#"Already signed in %#", auth);
NSLog(#"Window: %#", self.window);
// SHOW MainMenu.xib here
} else {
NSLog(#"Not signed in %#", auth);
loginController = [[LoginController alloc] initWithWindowNibName:#"Login" owner:self];
[[loginController window] makeKeyAndOrderFront:self];
}
}
I see that AppController's awakeFromNib gets called before the applicationDidFinishLoadingWithOptions. Would it be best to put that code in my awakeFromNib?
If not, what is the best way to open the MainMenu.xib window from the AppDelegate?
If you have a better approach, what would it be?
PS: AppController is a subclass of NSObject so I don't have access to windowDidLoad or windowWillLoad
awakeFromNib is the first method to get executed.
You can also use alloc or init methods.
You can put your login authentication codes there, without any problem.
You must have seen the application life-cycle, how and when what methods get loaded.

iOS using navigationController popToRootViewControllerAnimated

When I try to use popToRootViewControllerAnimated method my screen turns black.
I think I really get back to the expected view though because if I rotate my device to landscape the view appears correctly.
Here is the context of my application:
A viewcontroller A is nested into a navigation controller. Clicking on a button triggers a segue to viewcontroller B. In the viewDidLoad method of viewcontroller B a connection helper is created in order to collect some data on our server database. While being created the helper is checking if the device is connected to internet. If it's not then "popToRootViewControllerAnimated" is called to return to viewcontroller A.
Here is the code of the helper:
+(AFHTTPClient*) getClient {
if (!client) {
[self createClient];
}
if (client.networkReachabilityStatus <AFNetworkReachabilityStatusReachableViaWWAN) {
[currentController.navigationController popToRootViewControllerAnimated:YES];
//[[[UIAlertView alloc] initWithTitle:#"Connection Problem" message:#"You don't seem to be connected to internet. Please enable WI-Fi or 3G then try again." delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil] show];
client = nil;
}
return client;
}
+(void) createClient{
NSURL* baseUrl = [NSURL URLWithString:[[#"http://" stringByAppendingString:[ApplicationTask GetApiUrl]] stringByAppendingString:#"/"]];
client = [AFHTTPClient clientWithBaseURL:baseUrl];
client.parameterEncoding = AFJSONParameterEncoding;
[client registerHTTPOperationClass:[AFJSONRequestOperation class]];
[client setDefaultHeader:#"Accept" value:#"application/json"];
[client setDefaultHeader:#"Content-Type" value:#"application/json"];
}
Once the "popToRootViewControllerAnimated" method as been called, I can see the view from controller A sliding and a black screen is showing up.
As I mentioned earlier it feels like I am brought back to viewcontroller A (rotating the device from portrait to landscape orientation show the view) but the view seems like outside the frame of the screen.
Hope I made everything clear.
Thanks
As I mentioned into my comment, popping to the root controller in the viewDidAppear method seem to do the trick.

Generic "help" view which is accessible from all views in uinavigationView

Assuming an application has many views pushed to a uinavigationViewController, each view is different in content.
since the elements in the app are complex, I would like to show a small help view for specific views or elements in a specific view.
Imagine a "?" button that when pressed on will pop a new view in the center of the screen, playing youtube help video, or just a textual HTML loaded from a remote server.
Question: what is the best strategy for doing such a thing?
where should I place this code (App Delegate?)
if so, how would I call it from other views (with URL Parameter)
-(void)showHelpView:(NSString *)theURLString{
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)];
//webView.delegate= self;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:theURLString]]];
[window addSubview:webView];
[window makeKeyAndVisible];
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
}
I'd prefer using pseudo-modal views. So that you create view every time, and add it on top of current window. I've used this approach for OAuth 2.0 authorisation popup in my last app.
Basically you create custom UIViewController subclass, provide custom initialisator, such as, for example:
// - (id) initWithURL: (URL*)url {
// ...
// self.url = url;
// ...
// return self;
PseudoModalViewController* pmvc = [[PseudoModalViewController alloc] initWithURL:#"http://www.google.com/"];
After you've created view you add it on top of current window:
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
if(!window)
{
window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
}
[window addSubview:pmvc.view];
In, for example, viewDidLoad you load url obtained in initialisator:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}
You may even design UI in Interface Builer for that. As a last piece I'd recommend add to include full screen transparent background view to ensure that all views below are disabled.
Oh, almost forgot, you hide that view with just a simple [self.view removeFromSuperview]. Don't forget to provide correct memory management for that view (i.e. release it in time, etc).

Prompt login alert with Twitter framework in iOS5?

As you all may know, since iOS5 there is a native Twitter framework which make it easy to post tweets from your app.
Is there a way to prompt an alert that forwards the user to the settings app and ask for username and password?
I know that i could solve the problem with the following code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=TWITTER"]];
But thats undocumented code..
Thanks in advance
Regards Billy
(My first post on SO)
In iOS5.1, we should use TWTweetComposeViewController to show the dialog since apple rejects apps using prefs:root=TWITTER.
But, I didn't like showing the tweet screen and keyboard
so I figured out the way to hide them, but show the pop up screen.
UPDATE:
Apple approved my app using this trick.
TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init];
//hide the tweet screen
viewController.view.hidden = YES;
//fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1
viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if (result == TWTweetComposeViewControllerResultCancelled) {
[self dismissModalViewControllerAnimated:NO];
}
};
[self presentModalViewController:viewController animated:NO];
//hide the keyboard
[viewController.view endEditing:YES];
//this approach doesn't work since you can't jump to settings
// [self dismissModalViewControllerAnimated:NO];
You don't need to implement this, if you set up your Twitter integration to make a post on Twitter and iOS detects that there is no Twitter account set up it will do this automatically for you!
This is a screenshot of one of my apps running on my iPhone 4S on iOS 5.1
The removal of Preferences links is in reference to custom actions by the developer, as in linking to your own preferences menu. This does not apply because not only is Twitter a built in function of iOS 5 but the UIAlertView that pops up to notify you isn't handled by the developer, it is an automatic function of iOS.
Here i found the way :
Display custom alert if no twitter account has been setup on your device settings:
if (![TWTweetComposeViewController canSendTweet]) {
UIAlertView *alertViewTwitter = [[[UIAlertView alloc]
initWithTitle:#"No Twitter Accounts"
message:#"There are no Twitter accounts configured. You can add or create a Twitter account in Settings."
delegate:self
cancelButtonTitle:#"Settings"
otherButtonTitles:#"Cancel",nil] autorelease];
[alertViewTwitter show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex==0) {
TWTweetComposeViewController *ctrl = [[TWTweetComposeViewController alloc] init];
if ([ctrl respondsToSelector:#selector(alertView:clickedButtonAtIndex:)]) {
[(id <UIAlertViewDelegate>)ctrl alertView:alertView
clickedButtonAtIndex:0];
}
[ctrl release];
}
}
Hope this will make sense :)
It's not possible, although it should automatically ask the user to login, if the user isn't logged in already.
As of iOS 5.1 that feature has been removed, as seen here