forked from organicmaps/organicmaps
[iPhone] Added AlertView which cancels automatically when app goes to background
This commit is contained in:
parent
36c7d727f1
commit
1c670aa479
4 changed files with 63 additions and 0 deletions
13
iphone/Common/CustomAlertView.h
Normal file
13
iphone/Common/CustomAlertView.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
|
||||
/// Alert View which can automatically close when going to background
|
||||
/// and call CancelButtonIndex delegate
|
||||
@interface CustomAlertView : UIAlertView
|
||||
{
|
||||
}
|
||||
|
||||
- (id) initWithTitle:(NSString *)title message:(NSString *)message
|
||||
delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle
|
||||
otherButtonTitles:(NSString *)otherButtonTitles, ...;
|
||||
|
||||
@end
|
34
iphone/Common/CustomAlertView.mm
Normal file
34
iphone/Common/CustomAlertView.mm
Normal file
|
@ -0,0 +1,34 @@
|
|||
#import "CustomAlertView.h"
|
||||
|
||||
@implementation CustomAlertView
|
||||
|
||||
- (id) initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate
|
||||
cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...
|
||||
{
|
||||
if ((self = [super initWithTitle:title message:message delegate:delegate
|
||||
cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil, nil]))
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, otherButtonTitles);
|
||||
for (NSString * anOtherButtonTitle = otherButtonTitles; anOtherButtonTitle != nil; anOtherButtonTitle = va_arg(args, NSString*))
|
||||
[self addButtonWithTitle:anOtherButtonTitle];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:)
|
||||
name:UIApplicationDidEnterBackgroundNotification object:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) applicationDidEnterBackground:(id) sender
|
||||
{
|
||||
// We should not be here when entering back to foreground state
|
||||
[self dismissWithClickedButtonIndex:[self cancelButtonIndex] animated:NO];
|
||||
}
|
||||
|
||||
@end
|
1
iphone/Common/README.txt
Normal file
1
iphone/Common/README.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Contains reusable code snippets for all iOS projects
|
|
@ -68,6 +68,7 @@
|
|||
FA0660001286167A00FEA989 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = FA065FFE1286167A00FEA989 /* Default.png */; };
|
||||
FA0660031286168700FEA989 /* Default-Portrait.png in Resources */ = {isa = PBXBuildFile; fileRef = FA0660011286168700FEA989 /* Default-Portrait.png */; };
|
||||
FA0660041286168700FEA989 /* Default-Landscape.png in Resources */ = {isa = PBXBuildFile; fileRef = FA0660021286168700FEA989 /* Default-Landscape.png */; };
|
||||
FA34BECA1338D72F00FFB2A7 /* CustomAlertView.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA34BEC81338D72F00FFB2A7 /* CustomAlertView.mm */; };
|
||||
FA4135EA120A263C0062D5B4 /* CountriesViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA4135E2120A263C0062D5B4 /* CountriesViewController.mm */; };
|
||||
FA4135ED120A263C0062D5B4 /* SettingsManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA4135E7120A263C0062D5B4 /* SettingsManager.mm */; };
|
||||
FA46DA0512D414D200968C36 /* maps.update in Resources */ = {isa = PBXBuildFile; fileRef = FA46DA0412D414D200968C36 /* maps.update */; };
|
||||
|
@ -163,6 +164,8 @@
|
|||
FA065FFE1286167A00FEA989 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = SOURCE_ROOT; };
|
||||
FA0660011286168700FEA989 /* Default-Portrait.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-Portrait.png"; sourceTree = SOURCE_ROOT; };
|
||||
FA0660021286168700FEA989 /* Default-Landscape.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-Landscape.png"; sourceTree = SOURCE_ROOT; };
|
||||
FA34BEC81338D72F00FFB2A7 /* CustomAlertView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CustomAlertView.mm; sourceTree = "<group>"; };
|
||||
FA34BEC91338D72F00FFB2A7 /* CustomAlertView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomAlertView.h; sourceTree = "<group>"; };
|
||||
FA4135E1120A263C0062D5B4 /* CountriesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = CountriesViewController.h; path = Settings/CountriesViewController.h; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
||||
FA4135E2120A263C0062D5B4 /* CountriesViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; name = CountriesViewController.mm; path = Settings/CountriesViewController.mm; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
||||
FA4135E6120A263C0062D5B4 /* SettingsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SettingsManager.h; path = Settings/SettingsManager.h; sourceTree = SOURCE_ROOT; };
|
||||
|
@ -252,6 +255,7 @@
|
|||
29B97314FDCFA39411CA2CEA /* Maps */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
FA34BEC71338D6DB00FFB2A7 /* Common */,
|
||||
FA6E1F1B124E6B2800F59149 /* Platform */,
|
||||
FA4135DF120A25B90062D5B4 /* Settings */,
|
||||
080E96DDFE201D6D7F000001 /* Classes */,
|
||||
|
@ -377,6 +381,16 @@
|
|||
name = "Static Libraries";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
FA34BEC71338D6DB00FFB2A7 /* Common */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
FA34BEC81338D72F00FFB2A7 /* CustomAlertView.mm */,
|
||||
FA34BEC91338D72F00FFB2A7 /* CustomAlertView.h */,
|
||||
);
|
||||
name = Common;
|
||||
path = ../Common;
|
||||
sourceTree = SOURCE_ROOT;
|
||||
};
|
||||
FA4135DF120A25B90062D5B4 /* Settings */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -526,6 +540,7 @@
|
|||
FAF37F01126DCE6F005EA154 /* IPhonePlatform.mm in Sources */,
|
||||
49DD2B51132FA8880031D82E /* GuideViewController.mm in Sources */,
|
||||
FAFCB63613366E78001A5C59 /* WebViewController.mm in Sources */,
|
||||
FA34BECA1338D72F00FFB2A7 /* CustomAlertView.mm in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue