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
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

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Key Features of Swift Programming Language
  • Top 6 Programming Languages for Mobile App Development

Trending

  • Multiple Stakeholder Management in Software Engineering
  • A Complete Guide to Modern AI Developer Tools
  • Run Scalable Python Workloads With Modal
  • Building an AI Nutrition Coach With OpenAI, Gradio, and gTTS

Alert Controller In Objective-C

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

By 
Hitanshi Mehta user avatar
Hitanshi Mehta
·
Aug. 07, 19 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
14.6K 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

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • 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
  • [email protected]

Let's be friends: