iOS – Push notification alert is not shown when the app is running

I used code like this in my application delegate to mimic the notification alert when the app was active. You should implement the appropriate UIAlertViewDelegate protocol method(s) to handle what happen when the user taps either of the buttons. – (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { UIApplicationState state = [application applicationState]; if (state == UIApplicationStateActive) { … Read more

‘UIAlertView’ was deprecated in iOS 9.0. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead

See this Code Destructive and OK buttons in UIAlertController: let alertController = UIAlertController(title: “Destructive”, message: “Simple alertView demo with Destructive and Ok.”, preferredStyle: UIAlertControllerStyle.alert) //Replace UIAlertControllerStyle.Alert by UIAlertControllerStyle.alert let DestructiveAction = UIAlertAction(title: “Destructive”, style: UIAlertActionStyle.Destructive) { (result : UIAlertAction) -> Void in print(“Destructive”) } // Replace UIAlertActionStyle.Default by UIAlertActionStyle.default let okAction = UIAlertAction(title: “OK”, style: … Read more

Several UIAlertViews for a delegate

Tag the UIAlertViews like this: #define kAlertViewOne 1 #define kAlertViewTwo 2 UIAlertView *alertView1 = [[UIAlertView alloc] init… alertView1.tag = kAlertViewOne; UIAlertView *alertView2 = [[UIAlertView alloc] init… alertView2.tag = kAlertViewTwo; and then differentiate between them in the delegate methods using these tags: – (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if(alertView.tag == kAlertViewOne) { // … } else if(alertView.tag … Read more

Changing the background color of a UIAlertView?

Background of AlertView is an image And you can change this image UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:@”Atention” message: @”YOUR MESSAGE HERE”, nil) delegate:nil cancelButtonTitle:@”OK” otherButtonTitles:nil] autorelease]; [theAlert show]; UILabel *theTitle = [theAlert valueForKey:@”_titleLabel”]; [theTitle setTextColor:[UIColor redColor]]; UILabel *theBody = [theAlert valueForKey:@”_bodyTextLabel”]; [theBody setTextColor:[UIColor blueColor]]; UIImage *theImage = [UIImage imageNamed:@”Background.png”]; theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16]; … Read more

Dismiss UIAlertView after 5 Seconds Swift

A solution to dismiss an alert automatically in Swift 3 and Swift 4 (Inspired by part of these answers: [1], [2], [3]): // the alert view let alert = UIAlertController(title: “”, message: “alert disappears after 5 seconds”, preferredStyle: .alert) self.present(alert, animated: true, completion: nil) // change to desired number of seconds (in this case 5 … Read more