iPhone OS SDK – Single time showing popup for users
12/04/2010It may sometimes be useful to show a one time reminder to your user in your application. This might be asking for a iTunes review, additions to social networks or any other task that It may be rude to ask more than once.
That is exactly what I have put into my application SavingsGoal, with a single time popup in the about screen. This is shown in detail in the example below:
First in viewDidLoad(), I have a reference to the firstViewSocialPopup class.
- (void)viewDidLoad {
[super viewDidLoad];
//Internet Links
websiteURL = @“http://apps.duivesteyn.net“;
supportEmail = @“apps@duivesteyn.net“;
facebookURL = @“http://www.facebook.com/apps/application.php?id=107880612574963“;
twitterURL = @“de_applications”;
[self firstViewSocialPopup];
}
in my .h header file, I have of course added:
-(void)firstViewSocialPopup;
Back in the .m file class I have the method firstViewSocialPopup, which is just checking a NSUserDefaults setting and displaying a UIAlert.
-(void)firstViewSocialPopup{
NSString *socialPopup = [NSString stringWithFormat:@"%@", [[NSUserDefaults standardUserDefaults] objectForKey:@”toggle_social”]];
NSLog(@”Social Reminder Status: %@”,socialPopup);
if ([socialPopup isEqualToString: @"YES"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Social Networking” message:@”Would you help the development team by adding them on Social Networks?” delegate:self cancelButtonTitle:@”No Thanks” otherButtonTitles:@”Twitter”,@”Facebook”,nil];
[alert show];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@"NO" forKey:@"toggle_social"];
}
}
THe UIAlert has delegate self and so sends the button pressed to the UIAlertView delegate (which is its self). This will call the class: (void)alertView: (UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
And so, in the same class (.m file) I have the following method:
- (void)alertView: (UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
{
NSLog(@“in alertView action, buttonIndex: %u”,buttonIndex);
if (buttonIndex==1) {
NSLog(@“Open Twitter”);
//Custom Open Twitter Page Code
deHelpers *dehelper = [[deHelpers alloc] init];
[dehelper openTwitterAppForFollowingUser:@“de_applications"];
} else if (buttonIndex==2) {
NSLog(@“Open Facebook”);
//Custom Open Twitter Page Code
url = [NSURL URLWithString:@“http://www.facebook.com/apps/application.php?id=107880612574963"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
PWWebViewController *webController = [[PWWebViewController alloc] initWithRequest:request];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:webController];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:@selector(dismissModal)];
webController.navigationItem.leftBarButtonItem = cancelButton;
[cancelButton release];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
}
}
Hopefully, you can see the idea, its quite simple. I have included some extra parts in the code for those who are interested exactly how I implement the popup actions. Its using a previously discussed control: PWWebViewController and some DrTouch code: openTwitterAppForFollowingUser.

No comments yet.