I need to create an IPhone Application...Which will communicate with a website...so it requires username and password...Now I need to know how to save the username and password in iphone...I have already used NSuserdefaults...but that didnt solved my pblm....Also I need to restore the view...from where the user exits the application...So I request you to help me?
Regards and thanks for the support,
Syam
I am a bit paranoid about saving secure data (username/passwords) on plain text files such as plist files or NSUserDefaults.
Apple provides Keychain services to store secure data. It is slightly complicated, view the documentation Keychain Services Tasks for iPhone OS
They also provide Generic Keychain app to explore.
You can store the password on a regular file, or you can also store it on a SQLite database.
I had a logout functionality in the app I did recently.
I had a hierarchy as :
"BaseUITableViewController
^
|
"Any subclass of UITAbleView Controller used in project."
all of these subclasses had a "Logout" button and the method to call logout service was written in Base class.
as soon as the response for logout request is valid and the session is killed I call following method (which of your interest in contrast to the above text :))
-(void)gotoMainScreenOnLogout
{
self.navigationController.navigationBarHidden = YES;//to make the previous view invisible
self.navigationController.toolbarHidden=YES; //27 JUNE UPDATE
[self.view removeFromSuperview]; //27 JUNE UPDATE
// MYAPPViewController *homeViewController = [[MYAPPViewController alloc]initWithNibName:#"MYAPPViewController" bundle:nil];
MYAPP_LoginUIVIewController *homeViewController =[[MYAPP_LoginUIVIewController alloc] initWithNibName:#"MYAPP_LoginUIVIewController" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:homeViewController ];
[nc.navigationBar setBarStyle:UIBarStyleBlackOpaque];
//
UIWindow *MYAPP_window = [[[UIApplication sharedApplication] windows]objectAtIndex:0];
CATransition *transition = [CATransition animation];
transition.duration = 0.8;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFade;
transition.delegate = self;
//...
[MYAPP_window.layer addAnimation:transition forKey:nil];
[MYAPP_window removeAllSubviews]; // not needed anymore
[MYAPP_window addSubview:nc.view];
[homeViewController release];
}
hope this helps.
Related
I am using UIActivityViewController in my new app for Facebook Share Option.
But if the user not login to the device, it dont working.. When select setting, Login page not appearing..
IActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint];
[self presentViewController:activityVC animated:TRUE completion:nil];
What can i do on this..? Is that the Problem of my code or a Common Error..?
iOS 6 introduced both the UIActivityViewController class and Social Framework, both of which may be used to integrate Twitter, Facebook and Sina Weibo functionality into iOS 6 applications. For general purpose requirements, the UIActivityViewController and SLComposeViewController classes provide an easy to implement path to social network integration.
UIActivityViewController *activityController =[[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
self presentViewController:activityController animated:YES completion:nil];
In order to use the SLComposeViewController class, a number of steps should be performed in sequence. Firstly, the application may optionally check to verify whether a message can be sent to the specified social network service. This essentially equates to checking if a valid social network account has been configured on the device and is achieved using the isAvailableForServiceType: class method, passing through as an argument the type of service required from the following options:
SLServiceTypeFacebook
SLServiceTypeTwitter
SLServiceTypeSinaWeibo
this is how you start ActivityIndicatorView with Loading lable
UIActivityIndicatorView *tempSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
lable =[[UILabel alloc]init];
lable.center = self.view.center;
lable.text = #"Loading...";
lable.hidden=NO;
lable.backgroundColor = [UIColor clearColor];
lable.textColor = [UIColor blackColor];
[lable sizeToFit];
lable.center = CGPointMake(160, 255);
tempSpinner.center = self.view.center;
[self.view addSubview:tempSpinner];
[self.view addSubview:lable];
start where ever you want like this
[tempSpinner startAnimating];
stop it like this where ever you want
[tempSpinner stopAnimating];
hide unhide loading label as per requirement
I have a button on my view controller that presents my In App Purchases store.
storeSinglePlayer *ssp = [[storeSinglePlayer alloc] initWithNibName:#"storeSinglePlayer" bundle:nil];
//Animation Code
CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:ssp animated:NO];
The navigation controller successfully pushes this store on the screen. The store has a back button which executes the following code:
[self.request cancel];
self.request.delegate = nil;
self.request = nil;
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController popViewControllerAnimated:NO];
This executes successfully as well. But if I now click the button to show the store view controller again, I get the message:
-[storeSinglePlayer respondsToSelector:]: message sent to deallocated instance 0xd642df0
This is a very famous problem indeed. And as you'll notice in the code above, I have incorporated the suggestions I came across various posts on stackoverflow. The following code has been implemented:
[self.request cancel];
self.request.delegate = nil;
self.request = nil;
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
Also I have my property and corresponding synthesize set as:
#property (nonatomic, strong) SKProductsRequest *request;
#synthesize request = _request;
I have no clue, why is it crashing!
P.S: The project is ARC enabled.
Something is calling your ssp after it has been released by ARC. The code you posted doesn't make it clear where that is happening.
One thing that most likely would solve the problem would be to keep a reference with a member variable+property to your ssp in your class declaration, instead of createing a new one every time you click the button. Just init it once when your first viewcontroller loads and reuse it instead.
If you want to investigate further, you could try to comment out the blocks setting up the transition and see if it still crashes. Maybe the navigationcontroller makes some call after the ssp has been released.
When a message is sent to a deallocated instance, an object was released from the memory and you are attempting to use it again. ARC must be releasing the object since it is automatically detecting that you no longer need the it. Try adding one of the following to your header file.
#property (nonatomic, strong) storeSinglePlayer *ssp;
or
storeSinglePlayer *__strong ssp;
The important word above is strong. It tells ARC that you want to retain this object for later use.
I got where I was messing up. I was handling multiple rotations using the following code:
[[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:#"storeSinglePlayerLandscape"] owner:self options:nil];
[self viewDidLoad];
I realize now, this not the best practice, as it calls viewDidLoad multiple times. Still, that's not really the cause of the problem. It works fine, when the store is displayed only a few times and returned back to the previous view controller. But say after 10-15 times, there are too many requests which would return with the product and hence send the error , "message sent to deallocated instance".
I commented out the code, and it works fine now.
I know, this is a very typical problem, which most users might not face. But just in case, you used implemented some bad code like me, may be this information works!
I have recently set-up an in-app purchase mechanism in my app. During the purchase i would like to update an hud (i am using the mbprogresshud) according to two kinds of events: i start a purchase and i receive a validation of the purchase. The problem i am facing is that the hud is never updated with the one i want when the purchase is done (custom view):
When i click on the purchase button:
-(IBAction)buyButtonTapped:(id)sender {
self.hud = [[SCLProgressHUD alloc] initWithView:self.view];
[self.view addSubview:self.hud];
self.hud.labelText = #"Connecting...";
self.hud.minSize = CGSizeMake(100 , 100);
[self.hud show:YES];
...
}
When i receive a notification that the purchase was successful:
-(void)productPurchased:(NSNotification *)notification {
self.hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"checkmark_icon.png"]];
self.hud.mode = SCLProgressHUDModeCustomView;
self.hud.labelText = #"Thanks for your purchase!";
...
}
Setting the self.hud.customView property in the last method will trigger a [self setNeedsLayout]; and [self setNeedsDisplay] within the hud class but still i don't observe any change.
Any possible idea of what i am doing wrong here?
As mentioned on the mbprogress hud readme, update of the UI when tasks are performed on the main thread required a slight delay to take effect. What happen in my case is that the hud was a strong property of a popover controller that i dismiss immediately so i didn't get a chance to see the update happening. I now dismiss the controller in the completion block of:
-(void)showAnimated:(BOOL)animated
whileExecutingBlock:(dispatch_block_t)block completionBlock:(void
(^)())completion
And my code snippet look like like this for the dismiss:
[_hud showAnimated:YES whileExecutingBlock:^(void){
[self.successPurchaseSoundEffect play];
_hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"checkmark_icon.png"]];
_hud.mode = SCLProgressHUDModeCustomView;
_hud.labelText = #"Thanks!";
// We need to pause the background thread to let the music play and the hud be updated
sleep(1);}
completionBlock:^(void){
[self.delegate dismissPurchaseInfoController:self];
}];
I use cocos2d combined with AdMob , nomarl my app work great, but after hit the advertising and return the game, it wrong layout, my game is landscape!
Things changes after AdMob is involved. AdMob has a AD type "movie". After clicking the ad, it popups a full screen mode, and play a movie, and then back to the game. The game changes, originally, it is landscape mode, and after back from ad, it seems to be portrait mode, and the game is scaled, everything looks bad. I have tried to update the view controller / CCDirector after back from ad, but it doesn't work.
A workaround found: just rotate the device to the counterpart landscape mode and everything goes well again.
Just wonder if there is any way to prevent telling customers rotate it manually?
Have you encountered this before?
_viewController = [[UIViewController alloc] init];
_viewController.view = [[CCDirector sharedDirector] openGLView];
_admobView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
_admobView.adUnitID = ADMOB_PUBLISHER_ID;
_admobView.delegate = self;
GADRequest *request = [GADRequest request];
request.testing = YES;
[_admobView setRootViewController:_viewController];
[_admobView loadRequest:request];
[_viewController.view addSubview:_admobView];
I had a similar issue before, and the cause was that I created a new UIViewController and set it as rootViewController for AdMob view - just like what you are doing:
_viewController = [[UIViewController alloc] init];
_viewController.view = [[CCDirector sharedDirector] openGLView];
...
[_admobView setRootViewController:_viewController];
This leads to layout problems when returning from some kinds of advertisement. What I am doing now in my app is like:
adMobView.rootViewController = [RootViewController sharedInstance];
[[[CCDirector sharedDirector] openGLView] addSubview:adMobView];
where [RootViewController sharedInstance] is a class method which returns the only instance of RootViewController in the app. For details please refer to my answer to another question: https://stackoverflow.com/a/10222956/1241690
(For cocos2d 2.x, the second line should be:
[[[CCDirector sharedDirector] view] addSubview:adMobView];
)
I have included AdMob in my iphone app. I have the following code in my viewDidLoad method:
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
0.0,
320,
50)];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = ADMOB_BANNER_UNIT_ID;
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
GADRequest *r = [[GADRequest alloc] init];
r.testing = YES;
[bannerView_ loadRequest:r];
[r release];
This leaks. When I comment out the second last line ( [bannerView_ loadRequest:r]; ), the leak disappears. The only thing I changed in this code from the example provided by Google was to introduce the variable r so I could put AdMob in testing mode. In the code supplied by Google, bannerView_ is released by viewDidUnload. I looked for the loadRequest method but all I found was a definition in the GADBannerView.h file. As far as I can tell, there is no GADBannerView.m file, which seems weird in itself. Anyway, any tips would be much appreciated.
Thanks,
John
Why don't you use this AdMediator - it is very simple to configure and you don't have to worry about AdMob and iAds (if you want to use it) :
will swap in AdMob ads if no iAds are
available.
Are you releasing bannerView_ in your dealloc method or somewhere else appropriate ?
Instead of:
GADRequest *r = [[GADRequest alloc] init];
You could try:
GADRequest *r = [GADRequest request];