Show an image in the alert body of a local notification - ios

I am using Local Notifications, but I want to put an image in the message body of the alert. How can I do that?

I also searched for the same question. And found that we can't customize the UILocalNotification, so I handled this in application:didReceiveLocalNotification: by showing custom UIAlertView.

This should work. Give it a whirl:
UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 40, 40)];
UIImage *smiley= [UIImage imageNamed:#"smiley.png"];
[imageView setImage:smiley];
[smiley release];
[successAlert addSubview:imageView];
[imageView release];
[successAlert show];
[successAlert release];
Good luck,
Aurum Aquila

If you are using simple images like question mark, notification, etc. I suggest Ext JS which has a Icon type alert.
You can add your images as well.

Related

How to show the image via http url in AlertView in Objective-C?

I am developing in Objective-C , and I want to show the image via http url in AlertView ?
I already get the image url like:http://192.72.1.1/DCIM/100__DSC/SNAP0053.JPG , and convert the NSURL to NSString. But I can not show the image in AlertView , it is empty.
The code for convert the url to NSString and show in AlertView is like the following:
NSString *path = [url absoluteString];
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: path]];
UIImage *Image=[UIImage imageWithData:imageData];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Image" message:nil delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] init];
[imageView setImage:Image];
[alert addSubview:imageView];
[alert show];
But the AlertView did not show any image like the following picture.
Did I missing something ?
How to show the image via http url in AlertView in Objective-C ?
You cant add image in AlertView.
It was possible prior to iOS 7.
You can create a custom AlertView and add image to it.
Also check out this
https://github.com/wimagguc/ios-custom-alertview
No, you can't do that. Write a custom control with UIView which imitate the behavior of UIAlertView.
Some suggestions:
Never use addSubView on UIAlertView.
UIAlertView is deprecated use UIAlertController.
Reference UIAlertView Class Reference:
1)
The UIAlertView class is intended to be used as-is and does not
support subclassing. The view hierarchy for this class is private and
must not be modified.
2)
Important: UIAlertView is deprecated in iOS 8. (Note that
UIAlertViewDelegate is also deprecated.) To create and manage alerts
in iOS 8 and later, instead use UIAlertController with a
preferredStyle of UIAlertControllerStyleAlert.

iOS UIAlertView with photo

I wanted to use UIAlertView to show photo. I´m using code as below for showing the alert, however it doesn't work. It shows the title, some space and button OK nothing more. I have no idea if I´m doing something wrong, because I´m new in iOS.
-(IBAction)ButtonPressed:(id)sender
{
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"titel"
message:nil
delegate:nil //or self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(180, 10, 85, 50)];
[imageView setImage:#"dog.png"];
[av setValue:imageView forKey:#"accessoryView"];
[av show];
}
#Popeye is correct what he said : UIAlertView is meant to be used as-is and you shouldn't be messing with the view hierarchy this will get your app rejected from the Apple App review process. Please read Apple documentation regarding UIAlertViews. So you should NOT be using setValue: forKey:#"accessoryView" and/or addSubview:. Specific section below
Subclassing Notes
The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.
Solutions
1) Use 3 party such as CNPPopupController and many other available check this link
OR
2) create of your own.

Accessibility: On updating UIAlertView's message, the text that Voice over reads does not change?

Please refer the code below:
UIAlertView *progressAlertView = [[UIAlertView alloc]
initWithTitle:#"Title"
message:#"Message"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
progressAlertView.message=#"Hello, I am the new one";
Voice over always reads "Message" and never reads the new message string set in the second line "Hello, I am the new one". There's no way to change this accessibility label of the bodyTextLabel control/subView of UIAlertView.
Any idea how to make UIAlertView change its accessibility labels after its alloc'ed?
Thanks,
-Shilpi
You can use accessibilityTraits as UIAccessibilityTraitUpdatesFrequently to read updated message.
it works like:
alertObj.accessibilityTraits = UIAccessibilityTraitUpdatesFrequently;
Thanks
use this way for set message of UIAlertView
UIAlertView *progressAlertView = [[UIAlertView alloc]
initWithTitle:#"Title"
message:#"Message"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
[alertView setMessage:#"Hello, I am the new one"];
[alertView show];
For More About UIAlertView Refer this
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html
You can change the subviews of UIAlertView to change single attributes like the accessibility label:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Test"
message:#"Message"
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
// In a standard UIAlertView there are 2 UILabels and some buttons
// The UILabel with the message is always the 2nd object in the array
NSArray *subviews = alert.subviews;
UILabel *messageLabel = [subviews objectAtIndex:1];
[messageLabel setAccessibilityLabel:#"Some other text"];
With this code you only change the accessibility label, so that VoiceOver reads another text but the old text is shown.
In your case you should set the accessibility label to the same as you want to set the message of the UIAlertView.

how can I hide an empty tableview

I have a problem and I hope someone here can help me out! Thanks in advance.
I have a "Scope"button(see screen shot!) which is linked to a segue and the segue goes to a tableview.
What I want to do is in the tableview controller that I decide if I should display something in the table or I should throw out an alertview.
What I did was:
if ([_countryScopes count] == 0) {
[self.view removeFromSuperview];
//no scope for this country
NSMutableString *message = [[NSMutableString alloc]initWithString:#"No scope information."];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:countryName message:message delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
//av.tag = MAIN_ALERT;
[av show];
}
But somehow the empty table is still showing up.
Do you know, how I can get rid of this?
Thanks a lot!
Regards, Yashu
just show alert view after 0.1 seconds, i hope this will do the trick:
[av performSelector:#selector(show) withObject:nil afterDelay:0.1];

How to validate and restrict input to UITextField inside UIAlertView in iOS

I am using the UIAlertView to show the text field over a popup. But the problem I am facing is that I am not able to validate and restrict the entries in UITextField over a popup, i.e. I want to accept only 3 numeric values.
Here i am providing the block of code that I have implemented.
popup = [[UIAlertView alloc] initWithTitle:#"Please enter 3 numeric values"
message:#"\n\n"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok", nil];
txtFld = [[UITextField alloc] initWithFrame:CGRectMake(12, 50, 260, 25)];
[txtFld setBackgroundColor:[UIColor whiteColor]];
[txtFld setKeyboardType:UIKeyboardTypeNumberPad];
[popup addSubview:txtFld];
[popup show];
[txtFld becomeFirstResponder];
So can anyone help me out to resolve this issue? Thanks in advance.
here I can see that you have not set textfield.delegate=self , please check it in your code
It is risky to manually add subviews to UIAlertView or any other view you do not control as its hierarchy is private and subject to change. If you're targeting iOS 5 or above, you can use one of the UIAlertView styles that supports text entry and validation such as UIAlertViewStylePlainTextInput. The documentation for UIAlertView provides a list of styles and this tutorial explains their use in more detail.

Resources