DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Migrate, Modernize and Build Java Web Apps on Azure: This live workshop will cover methods to enhance Java application development workflow.

Modern Digital Website Security: Prepare to face any form of malicious web activity and enable your sites to optimally serve your customers.

Kubernetes in the Enterprise: The latest expert insights on scaling, serverless, Kubernetes-powered AI, cluster security, FinOps, and more.

A Guide to Continuous Integration and Deployment: Learn the fundamentals and understand the use of CI/CD in your apps.

Related

  • Key Features of Swift Programming Language
  • Top 6 Programming Languages for Mobile App Development
  • Input Alert in Objective-C

Trending

  • Building Your Own AI Chatbot With React and ChatGPT API
  • Unlocking the Power of Streaming: Effortlessly Upload Gigabytes to AWS S3 With Node.js
  • What Are the Pillars of API Security?
  • Demystifying Databases, Data Warehouses, Data Lakes, and Data Lake Houses

Alert Controller In Objective-C

Learn how to use Xcode and objective-C to create a Security alert.

Hitanshi Mehta user avatar by
Hitanshi Mehta
·
Aug. 07, 19 · Tutorial
Like (2)
Save
Tweet
Share
13.4K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

We have seen a security alert in iOS applications that looks like the following image:

Information Alert In Xcode Using Objective-C

In this article, we will learn how to create a security alert in Objective-c using Xcode. If you are a beginner and need help getting started, check out this tutorial on getting started with Xcode. 


Step 1

Add button from library.  Add button from the object library.


Open up the object library and add a button to your screen. 

Adjust button.    Adjust button

Then, adjust the button on the screen. 

Step 2

Add contrains.Add Constraints.


Provide constrain with the help of Resolve layout issue on bottom middle.

If a warning is still there, then select update missing constraints.

Update Constraints.

Step 3

To uniquely identify the event on the component, we need to provide a name to the event. To provide a unique name to the event open, ViewController.h and Main.storyboard at the same time with the help of an assistant editor.

Step 4

Add touch up inside.


Make sure that Main.StoryBoard and viewController.h files are open. If these files are not open, you can change it from the top of the screen (highlighted with box).

Right-click on the button. Select touch up inside. This will allow you to perform any task on button click.

Step 5

Information Alert In Xcode Using Objective-C

Provide a name for touch up inside event.


Once you will release the cursor, the following pop-up will appear. Here you can provide a unique name for the event. Click Connect.

Now we will write some code.

Step 6

Information Alert In Xcode Using Objective-C

In the alert box, we need three things:

1. Alertbox With Heading

@implementation ViewController- (void)viewDidLoad {  
  [super viewDidLoad];  
  // Do any additional setup after loading the view, typically from a nib.  
}  
-(void)InformativeAlertWithmsg:(NSString *)msg  
{  
  UIAlertController *alertvc=[UIAlertController alertControllerWithTitle:@"Security alert" message:msg preferredStyle:UIAlertControllerStyleAlert];  
}  


First, create a method that takes a string as a parameter.

In that method, create an instance of UIAlertController. This will provide a heading and display a text message. You will pass your desired message as the argument.

2. Dismiss Button

-(void) InformativeAlertWithmsg: (NSString * ) msg {  
  UIAlertController * alertvc = [UIAlertController alertControllerWithTitle: @ "Security alert"  
                                 message: msg preferredStyle: UIAlertControllerStyleAlert  
                                ];  
  UIAlertAction * action = [UIAlertAction actionWithTitle: @ "Dismiss"  
                            style: UIAlertActionStyleDefault handler: ^ (UIAlertAction * _Nonnull action) {  
                              NSLog(@ "Dismiss Tapped");  
                            }  
                           ];  
  [alertvc addAction: action];  
  [self presentViewController: alertvc animated: true completion: nil];  
}  


Create an instance of UIAlertAction that provides title and default style. Then, double click on the handler and ensure that action is performed.

We have created action and alert but they are not connected. We can connect them using addAction. We then need to connect an action controller to the current view controller using presentViewController.

3. Information Message

- (IBAction)btnInfoAlert:(id)sender {  
  [self InformativeAlertWithmsg:@"Please check network connectivity"];  
}  


We have created an alert controller with action(Dismiss button), now we will provide information message. For that call, a method from a button touchup inside the event. While calling method provide information message as an argument.

Output


Information Alert In Xcode Using Objective-C

Information Alert In Xcode Using Objective-C

Information Alert In Xcode Using Objective-C

I hope that the concept is clear to you. If you have any questions, ask in the comment section!!

Objective C

Opinions expressed by DZone contributors are their own.

Related

  • Key Features of Swift Programming Language
  • Top 6 Programming Languages for Mobile App Development
  • Input Alert in Objective-C

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: