I've got a problem,
I added Flurry SDK in my iOS app and want to show a full screen add each time when the user click in the "Ok" button of an uiAlertView. The problem is that it doesn't work.
So, I tried try to do it without the AlertView and it works perfectly.
Someone knows why it doesn't work after clicking on an AlertView.
// The call of the alertview
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"TitlePopupNewGame", nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(#"CancelPopupNewGame", nil) otherButtonTitles:NSLocalizedString(#"YesPopupNewGame", nil), nil];
myAlert.tag = 1;
myAlert.delegate = self;
[myAlert show];
// Alertview method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView.tag == 1 && buttonIndex == 0){
[self showInterstitial];
}
}
// ShowInterstitial method
-(void) showInterstitial{
if ([FlurryAds adReadyForSpace: #"Full screen banner"]) {
[FlurryAds displayAdForSpace: #"Full screen banner"
onView:mv];
[FlurryAds fetchAdForSpace:#"Full screen banner"
frame:mv.frame size:FULLSCREEN];
} else {
// fetch an ad
[FlurryAds fetchAdForSpace:#"Full screen banner"
frame:mv.frame size:FULLSCREEN];
}
}
Thanks
Related
How to dismiss uialertview(default) when click on out side. Here I have set the uialert with only one button (OK). Intend for implement this alert, if user seen free offer pack from this uialertview and he want to access his free pack offer by clicking the OK button in uialertview. Otherwise if he doesn't want to access his free offer pack at this time the user can tap the outside of uialert view and the alertview dismissed it.
Kindly give suggestion for how dismiss uialertview from out side clicking.
offeredAlert = [[UIAlertView alloc] initWithTitle:nil
message:strMessage
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil,nil];
[offeredAlert setTag:10002];
[offeredAlert show];
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *tempStr;
if(alertView.tag == 10001)
{
if(buttonIndex == 1)
{
tempStr = #"payable";
[self dietPackPurchaseAPI:id_Pack type:tempStr];
}
}
}
Let's say John has been using my app for 3-6 minutes.
Then I'd like a view to pop up that would in my case, include an advertisement.
Something like this,
AdViewController *adViewController = [[AdViewController alloc] init];
[self presentViewController:adViewController animated:YES completion:nil];
But how can I let it pop up after some random time? I guess I have to work with the delegate files and use the arc4random function.
After John has viewed the advertisement, he'd then have to close it, but that's not the problem..
Can someone give me a code example?
The simple solution is to
Create a NSTimer and let it fire every 300 secs (5 mins)
NSTimer will fire an action that shows your pop-up.
I don't get it why was this so difficult to understand?
//use arc4random() if you need random time
NSTimer *timer2 = [NSTimer scheduledTimerWithTimeInterval:300.0 target:self selector:#selector(rateThisApp) userInfo:nil repeats:YES];
// *********
// ********* RATE APP ***********
// *********
- (IBAction)rateThisApp
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Rate this App"
message:#"Are you enjoying this app? Please leave a rating at the app store and tell us what you think of this app and its features. We would love to hear from you!"
delegate:self cancelButtonTitle:#"Not Now"
otherButtonTitles:#"Rate Now", nil];
[alert show];
alert.tag = 400;
}
-(void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (actionSheet.tag == 400)
{
if (buttonIndex == 0)
{
//dont do anything, user hit cancel
}
else if (buttonIndex == 1)
{
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:#"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=1234567"]];
}
}
}
I am using UIImagePickerController to capture video from my app and i have set video maximum duration to 30 seconds. When that 30 seconds limit is reached. I get an alert with a message "maximum video recording limit reached" produced by UIImagePickerController and it stops capturing video.
What I want is that I want to respond to that alert that is generated automatically when 30 seconds limit is reached. I want to perform some action when "OK" button of that alert is pressed. I have implemented all the delegate methods of UIAlertView but it does come in any method when I press OK button.
Please help me how I can respond to that alert?
You can't use all those delegate methods because you didn't initiate the UIAlertView so you can't set his delegate...
The only thing I can think about is to do somethong like listening to the UIWindowDidBecomeVisibleNotification to detect when an alert is shown and to the UIWindowDidBecomeHiddenNotification notification to detect when it disappears.
You should know that those notification will fire for all kind of components that uses their own UIWindow such as UIActionSheet or the keyboard, so you need to make sure this is the right one (maybe check to see if there is a UIAlertView in one of the subviews..)
Set yourself as a delegate of your UIImagePickerController, and implement the UIImagePickerControllerDelegate protocol. Specifically, the following method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)
Use UIAlertViewDelegateProtocol
Form docs
alertView:clickedButtonAtIndex:
Sent to the delegate when the user
clicks a button on an alert view.
(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex Parameters alertView The
alert view containing the button. buttonIndex The index of the button
that was clicked. The button indices start at 0. Discussion The
receiver is automatically dismissed after this method is invoked.
Availability Available in iOS 2.0 and later. Declared In UIAlertView.h
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{
// do stuff for button index 0,ie cancel button and sthe same for other button indeces
}
}
Please refer this tutorials : http://mobile.tutsplus.com/tutorials/iphone/uialertview/ you can get more ideal about this :
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Hello World!"
message:#"This is your first UIAlertview message."
delegate:self
cancelButtonTitle:#"Button 1"
otherButtonTitles:#"Button 2", #"Button 3", nil];
[message show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Button 1"])
{
NSLog(#"Button 1 was selected.");
}
else if([title isEqualToString:#"Button 2"])
{
NSLog(#"Button 2 was selected.");
}
else if([title isEqualToString:#"Button 3"])
{
NSLog(#"Button 3 was selected.");
}
}
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have this 2-button alert view:
UIAlertView* message = [[UIAlertView alloc]
initWithTitle: #"Delete?" message: #"This business will be deleted permenently." delegate: nil
cancelButtonTitle: #"Cancel" otherButtonTitles: #"Delete", nil];
[message show];
I also have this method:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Delete"])
{
NSLog(#"Button DELETE was selected.");
}
else if([title isEqualToString:#"Cancel"])
{
NSLog(#"Button CANCEL was selected.");
}
}
and I added this to the .h file:
<UIAlertViewDelegate>
Right now when either button is pressed, it just closes the dialog. That is ok for cancel, but how do I know when the delete button is pressed?
Thanks!
You have to implement the – alertView:clickedButtonAtIndex: method of the UIAlertViewDelegate. You also have to set the delegate when initialising the alert view.
E.g.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
//Do something
} else if (buttonIndex == 1) {
//Do something else
}
}
The cancel button's index is 0.
You are passing nil to the delegate parameter when you create the alert view. You need to pass self instead. As you have it now, the clickedButtonAtIndex: method is never called.
UIAlertView* message = [[UIAlertView alloc]
initWithTitle: #"Delete?"
message: #"This business will be deleted permenently."
delegate: self
cancelButtonTitle: #"Cancel"
otherButtonTitles: #"Delete", nil];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == alertView.cancelButtonIndex) {
// Cancel was tapped
} else if (buttonIndex == alertView.firstOtherButtonIndex) {
// The other button was tapped
}
}
message.delegate = self;
...
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(#"Button %d was clicked", buttonIndex);
}
and the class must be declared to meet the UIAlertViewDelegate protocol.
I created an alert view with three buttons -"Sign Up","Donate","Cancel"- when u click on either sign up or donate, safari should open with the specific website. However when I open the app, and click any of the buttons, safari doesn't open or do anything and the buttons work as though they were different versions of the cancel button. Here is my code:
In BlahBlah.h:
#interface BlahBlah: UIViewController <UITextFieldDelegate, UIAlertViewDelegate> {
}
#end
In BlahBlah.m:
#define donate_tag 0
#import "BlahBlah.h"
#implementation BlahBlah
...
- (void) donate {
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:#"Donate"
message:#"Function doesn't work yet :(" delegate:nil cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Sign Up",#"Donate",nil];
alert2.tag = donate_tag;
[alert2 show];
[alert2 release];
}
...
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(alertView.tag == donate_tag && buttonIndex == 1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com"]];
}
else if(alertView.tag == donate_tag && buttonIndex == 2){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.yahoo.com"]];
}
}
...
#end
You need to tell the alert who handles the actions of the buttons, that is to say, who is the "delegate" of the alert view.
Since everything related to the UIAlertView is within your "BlahBlah" view controller, after creating alert2, do something like this:
alert2.delegate = self;
or declare it in your UIAlertView instantiation:
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:#"Donate"
message:#"Function doesn't work yet :(" delegate:self
cancelButtonTitle:#"Cancel" otherButtonTitles:#"Sign Up",#"Donate",nil];