iOS 7 screenshots:
iOS 6 screenshots:
The app pauses for three seconds with a white screen and white status bar
(black text on top of the status bar).
Then it displays a
UIAlertView
with four buttons.
If you press Ignore,
it will wait for three more seconds and then display a
UIActionSheet
with five butons.
If you press
Call Premier Khrushchev,
it will launch the Safari app and go to the
Wikipedia article
for Nikita Khrushchev.
See the novel
Fail-Safe,
the
film
(Henry Fonda,
Walter Matthau),
and the
video
(George Clooney,
Harvey Keitel).
A
UIAlertView
pops in out of nowhere.
A
UIActionSheet
slides up from the bottom of a
UIView
.
See
Alert
Views
and
Action
Sheets
in the
Human
Interface Guidelines.
A
UIAlertView
has a delegate that adopts the protocol
UIAlertViewDelegate
.
A
UIActionSheet
has a delegate that adopts the
UIActionSheetDelegate
protocol.
Our
ViewController
plays the rôle of both delegates.
main.m
AlertAppDelegate
ViewController
calls the
showAlert:
showActionSheet:
View
.
View
Alert-Info.plist
:
in older versions of iOS, the
information
property list
file had to contain the key
CFBundleURLTypes
.
A list of
enumerations
is a series of variables that hold consecutively numbered integers
starting at zero by default.
See the two lists at the top of
ViewController.m
.
The URL
http://en.m.wikipedia.org/wiki/Nikita_Khrushchev
is formatted for a browser on a mobile device.
The URL
http://en.wikipedia.org/wiki/Nikita_Khrushchev
is formatted for a browser on a desktop computer.
Both URLs have one underscore.
I had to write
{
curly
braces}
around the
case actionKhrushchev:
of the
switch
statement
in the
actionSheet:clickedButtonAtIndex:
ViewController
because I declared variables in this
case
.
If the user presses the
“Call Premier Khrushchev”
button of the
UIActionSheet
,
the
applicationWillResignActive:
applicationDidEnterBackground:
case actionkhrushchev:
switch
statement in the
actionSheet:clickedButtonAtIndex:
ViewController
.
When we press the Home button to stop Safari and resume this app, the
applicationWillEnterForeground:
applicationDidBecomeActive:
The URL can begin with one of the following schemes.
Only
http:
http:
https:
tel:
mailto:
@"http://maps.google.com/maps?q=Moscow"
scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:
,
would it be easier to call the
performSelector:withObject:afterDelay:
we saw here?Segmented
,
display a
UIAlertView
.
Any URL starting with
http:
openURL:
alert:
Alert
app.
See
Registering
Custom URL Schemes.
Alert-Info.plist
Supporting Files
folder in XCode’s Project Navigator.
Add a new key whose name is
CFBundleURLTypes
and whose value is an array of dictionaries
that announces that another app can launch this one with any
URL starting with
alert:
.Alert-Info.plist
TextEdit.app
,Alert-Info.plist
in the Project Navigator and selecting
Open As → Soure Code
.
When you are done editing,
remove the app from the simulator and run it again.
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>edu.nyu.scps.Alert</string> <key>CFBundleURLSchemes</key> <array> <string>alert</string> </array> </dict> </array>
application:didFinishLaunchingWithOptions:
return YES;
.
It uses the
application
argument passed to
application:didFinishLaunchingWithOptions:
.NSURL *url = [NSURL URLWithString: @"alert:"]; if (![application canOpenURL: url]) { NSLog(@"can't open URL \"%@\", url); return YES; } NSLog(@"[application openURL: \"%@\"] == %d", url, [application openURL: url]);
NSURL *url = [NSURL URLWithString: @"alert:hello"];To receive this information, insert these statements into the
application:didFinishLaunchingWithOptions:
method of the Alert app.
NSURL *url = [launchOptions objectForKey: UIApplicationLaunchOptionsURLKey]; NSString *s = url == nil ? @"" : [url description];If the Alert app was launched by a second app, the string
s
in the Alert app will now be the URL that the second app used
(in this case @"alert:hello
"),
including the information after the colon.
If the Alert app was launched by a finger tapping on the Alert app’s icon,
the string s
in the Alert app will be the empty string
@""
.
Launch the Alert app by pressing the Xcode Run button
before you launch the Alert app by running the second app.