UIAlertView for user to download another app - objective-c

I downloaded an app from app store and noticed that once I installed and opened the app, I got a UIAlertView suggesting that I download another app..
How can I achieve this? Are there any existing code that I can be directed towards?
Seems like a simple feature but I'd like to integrate it. Please see attachment
Here is my edited code, but the 'Hello' button won't link anywhere.. What am I doing wrong?
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Hello World!"
message:#"This is your first UIAlertview message."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"Hello", nil];
[message show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Hello"])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"https://itunes.apple.com/gb/app/islam/id667021108?mt=8&affId=1930871&ign-mpt=uo%3D4"]];
}
}

first you have to make alertView, if you want to show the alert as first thing but this code inside (ViewDidLoad) method
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"your title"
message:#"your message"
delegate:self
cancelButtonTitle:#"Not now"
otherButtonTitles:#"Download now"
, nil];
[alert show];
after viewDidLoad but this method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != [alertView cancelButtonIndex]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"here but your application link"]];
}else{
}
}
//=================================================//
To know what's NSUserDefaults, I suggest to take a look the official doc.
And of course you can use it to fulfill your goal. You use a user default to store information about the current amount of runs in the app.
More or less like:
BOOL NotTheFirstTime = [[NSUserDefaults standardUserDefaults] boolForKey:#"NotTheFirstTime"];
if(!NotTheFirstTime){
// Show the alert view
// Then set the first run flag
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"NotTheFirstTime"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
if that help you please make it the best question.

It is pretty simple:
1) Set up an UIAlertView as usual with the text and the button titles you like.
2) Set up the UIAlertView's delegate and use this method to figure out which button was clicked (whether the user does or does not want to go to the App Store):
alertView:clickedButtonAtIndex:
3) If the user wants to go to the App Store, open up an App Store link:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"<#This is your App Store Link#>"]];

Related

how to dismiss all the alertviews opened in iOS7

I am new to iOS.I am developing an application which contain notifications.While using the app when a notification arrives an alertView is displayed.Everything works fine but if notification arrives when another alertView is already displayed problem starts.Notification alertView is displayed above the existing alertView.When I click OK for the notification alertView UI navigates to a new view controller and there the fist alertView remains displayed.If i click on that alertView my app crashes.
Is there any way to close all the alertviews that is displayed, when I click on the notification alertView.
I got this solution
for (UIWindow* window in [UIApplication sharedApplication].windows)
{
NSArray* subviews = window.subviews;
if ([subviews count] > 0)
if ([[subviews objec`enter code here`tAtIndex:0] isKindOfClass:[UIAlertView class]])
[(UIAlertView *)[subviews objectAtIndex:0] dismissWithClickedButtonIndex:[(UIAlertView *)[subviews objectAtIndex:0] cancelButtonIndex] animated:NO];
}
But this code works for iOS6 not iOS7.
I want a corresponding code in iOS7.
Can anyone please help.Thanks in advance
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:#"title" message:#"message" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alert1 show];
[self performSelector:#selector(dismiss:) withObject:alert1 afterDelay:1.0];
-(void)dismiss:(UIAlertView*)alert
{
[alert dismissWithClickedButtonIndex:0 animated:YES];
}

Load a web view after opening a notification alert?

I made a RSS app, it works perfectly, I also added Push Notification Support, everything is good so far, am passing a title, alert, and a url as an extra field.
When my notification arrives, I show my alert, and you have 2 options "Thanx | Open"
All I want to do now is, when you click open from this alert, I need to redirect my user to a view that has a UIwebview and load the url I passed along with the notification.
Can anyone help me?
Here is my code:
// here is my app delegate
-(void)onReceivePushNotification:(NSDictionary *) pushDict andPayload:(NSDictionary *)payload {
[payload valueForKey:#"title"];
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"New Alert !" message:[pushDict valueForKey:#"alert"] delegate:self cancelButtonTitle:#"Thanks !" otherButtonTitles: #"Open",nil];
NSLog(#"message was : %#", [pushDict valueForKey:#"alert"]);
NSLog(#"url was : %#", [payload valueForKey:#"url"]);
[message show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Open"]) {
[[Pushbots getInstance] OpenedNotification];
// Decrease Badge count by 1
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:[UIApplication sharedApplication].applicationIconBadgeNumber -1];
// Decrease badge count on the server
[[Pushbots getInstance] decreaseBadgeCountBy:#"1"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"updateRoot" object:nil];
} else {
// set Badge to 0
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
// reset badge on the server
[[Pushbots getInstance] resetBadgeCount];
}
}
My detail view is called : "APPDetailViewController", with a web view called "webView"
Please help me?
Thanks in advance.
You could create an instance of APPDetailViewController in your clickedButtonAtIndex method and present it. If you have tabs, you can switch to that tab, and then have a method to pass the url to so that it opens that page.

Prevent from UIAlertView to repeat when click on tableViewCell

I'm kinda stuck with a stupid problem, in my app when a user press on a TableViewCell he can change some value in the server, before i am sending the information to server i want to show UIAlertView to the user to make sure he wants to do that.
so in didSelectRowAtIndexPath:
i wrote this
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Caution!" message:#"bla bla " delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[alert show];
then its calls the UIAlertView method clickedButtonAtIndex:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
NSString *url = #"some url";
NSDictionary *paramerter = #{#"parameter":parameter};
[self.jsonHandler startParseWithParameters:paramerter andUrlAdress:url withCompletion:^(int errValue) {
if (errValue == 1) {
NSLog(#"ERROR");
}else if (errValue == 0){
[self AlertViewWithTitle:#"success" andMessage:#"success"];
}
}];
}
}
the problem is that the if (buttonIndex == 0) called for every cell and change them all!
and i get UIAlertView message for every cell in the tableView.
how can i prevent it?
EDIT
Ok the problem caused because i use the same buttonIndex for both UIAlertViews
i solved it using this:
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"buttonString"]){
//Do what ever you need
}
hope someone find it helpful.

Basic use of UIAlertView causes EXC_BAD_ACCESS

I'm implementing a very simple iOS application just to practice showing a pop up alert in, and I get an error when I press the alert button:
Thread 1:EXC_BAD_ACCESS(code=1,address=0x676f6f57)
This is the code:
- (IBAction)AlertButton {
alert = [[UIAlertView alloc]
initWithTitle:#"Alert" message:#"Alert"
delegate:self
cancelButtonTitle:#"Dismiss"
otherButtonTitles:#"Apple", "Google" ,nil];
[alert show];}
-(void)alertView :(UIAlertView *)alertView clickedButttonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 1){
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:#"http://apple.com"]];
}
if(buttonIndex == 2){
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:#"http://google.com"]];
}}
the problem is with the constructor of the UIAlertView, in the line:
otherButtonTitles:#"Apple", "Google" ,nil];
your forget the # before "Google". And finally change:
-(void)alertView :(UIAlertView *)alertView clickedButttonAtIndex:(NSInteger)buttonIndex{
by
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
The real problem is you miss an # in front of "Google", so it is not an NSString and hence the crash.
use this
.h
no need for IBOutlet.just
UIAlertView *alert;
.m
alert = [[UIAlertView alloc]
initWithTitle:#"Alert"
message:#"Alert"
delegate:self
cancelButtonTitle:#"Dismiss"
otherButtonTitles:#"Apple", #"Google", nil
];

Whats wrong with this code? (objective-c)?

-(void)otherGames
{
UIAlertView *alertMsg = [[UIAlertView alloc]
initWithTitle:#"This gGame was Developed By:"
message:#"Burhan uddin Raizada"
delegate:nil
cancelButtonTitle:#"Dismiss"
otherButtonTitles: #"#twitter" , nil];
[alertMsg show];
}
-(void)alertMsg:(UIAlertView *)alertMsg clickedButtonAtIndex:(NSInteger)buttonIn… {
if (buttonIndex == 1) {
NSString *containingURL = [[NSString alloc] initWithFormat:#"http://www.twitter.com/…
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: containingURL]];
}
}
the first alertmsg is working absolutely fine. but when i added a like to the new "#twitter" button, then it just doesn't work. otherwise everything is working fine. i am wondering why it doesn't, but it should..need help.
Assuming that
- (void)alertMsg:(UIAlertView *)alertMsg clickedButtonAtIndex:(NSInteger)buttonIn…
is
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
You must set your delegate to self and add the delegat protocol to your header :
#interface yourView : UIViewController <UIAlertViewDelegate>
Edit : According to #holex, use alertView:willDismissWithButtonIndex: instead of -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
UPDATE
this answer has been outdated since UIAlertView is deprecated in iOS8.
you can read more about UIAlertController on Apple's Dev Docs.
FIRST:
you haven't delegated your class, delegate:nil shows there is no delegated class for the UIAlertView. your should correct your method following this:
-(void)otherGames
{
UIAlertView *alertMsg = [[UIAlertView alloc]
initWithTitle:#"This gGame was Developed By:"
message:#"Burhan uddin Raizada"
// delegate:nil
delegate:self // don't forget to implement the UIAlertViewDelegate protocol in your class header
cancelButtonTitle:#"Dismiss"
otherButtonTitles: #"#twitter" , nil];
[alertMsg show];
}
SECOND:
the correct name of the callback method is: -alertView:didDismissWithButtonIndex:
//-(void)alertMsg:(UIAlertView *)alertMsg clickedButtonAtIndex:(NSInteger)buttonIn… { // WRONG, where have you got this silly idea...?
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
NSString *containingURL = [[NSString alloc] initWithFormat:#"http://www.twitter.com/…
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: containingURL]];
}
}
now, you know why your code fragment is wrong.