├── .gitignore ├── Example ├── PSTAlertViewControllerSample.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── PSTAlertViewControllerSample │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard │ ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── LICENSE ├── PSTAlertController.podspec ├── PSTAlertController ├── PSTAlertController.h └── PSTAlertController.m └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | .DS_Store 20 | 21 | # CocoaPods 22 | # 23 | # We recommend against adding the Pods directory to your .gitignore. However 24 | # you should judge for yourself, the pros and cons are mentioned at: 25 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 26 | # 27 | # Pods/ 28 | -------------------------------------------------------------------------------- /Example/PSTAlertViewControllerSample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 78E298891A0D0071007953FB /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 78E298881A0D0071007953FB /* main.m */; }; 11 | 78E2988C1A0D0071007953FB /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 78E2988B1A0D0071007953FB /* AppDelegate.m */; }; 12 | 78E2988F1A0D0071007953FB /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 78E2988E1A0D0071007953FB /* ViewController.m */; }; 13 | 78E298921A0D0071007953FB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 78E298901A0D0071007953FB /* Main.storyboard */; }; 14 | 78E298941A0D0071007953FB /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 78E298931A0D0071007953FB /* Images.xcassets */; }; 15 | 78E298971A0D0071007953FB /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 78E298951A0D0071007953FB /* LaunchScreen.xib */; }; 16 | 78E298B21A0D0B25007953FB /* PSTAlertController.m in Sources */ = {isa = PBXBuildFile; fileRef = 78E298B11A0D0B25007953FB /* PSTAlertController.m */; }; 17 | B87AF4971A67D76C00022878 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B87AF4961A67D76C00022878 /* UIKit.framework */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 78E298831A0D0071007953FB /* PSTAlertViewControllerSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PSTAlertViewControllerSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 78E298871A0D0071007953FB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 23 | 78E298881A0D0071007953FB /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 24 | 78E2988A1A0D0071007953FB /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 25 | 78E2988B1A0D0071007953FB /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 26 | 78E2988D1A0D0071007953FB /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 27 | 78E2988E1A0D0071007953FB /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 28 | 78E298911A0D0071007953FB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 29 | 78E298931A0D0071007953FB /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 30 | 78E298961A0D0071007953FB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 31 | 78E298A11A0D0071007953FB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | 78E298A21A0D0071007953FB /* PSTAlertViewControllerSampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PSTAlertViewControllerSampleTests.m; sourceTree = ""; }; 33 | 78E298B01A0D0B25007953FB /* PSTAlertController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PSTAlertController.h; sourceTree = ""; }; 34 | 78E298B11A0D0B25007953FB /* PSTAlertController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PSTAlertController.m; sourceTree = ""; }; 35 | B87AF4961A67D76C00022878 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 36 | /* End PBXFileReference section */ 37 | 38 | /* Begin PBXFrameworksBuildPhase section */ 39 | 78E298801A0D0071007953FB /* Frameworks */ = { 40 | isa = PBXFrameworksBuildPhase; 41 | buildActionMask = 2147483647; 42 | files = ( 43 | B87AF4971A67D76C00022878 /* UIKit.framework in Frameworks */, 44 | ); 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | /* End PBXFrameworksBuildPhase section */ 48 | 49 | /* Begin PBXGroup section */ 50 | 78E2987A1A0D0071007953FB = { 51 | isa = PBXGroup; 52 | children = ( 53 | B87AF4961A67D76C00022878 /* UIKit.framework */, 54 | 78E298851A0D0071007953FB /* PSTAlertViewControllerSample */, 55 | 78E2989F1A0D0071007953FB /* PSTAlertViewControllerSampleTests */, 56 | 78E298841A0D0071007953FB /* Products */, 57 | ); 58 | sourceTree = ""; 59 | }; 60 | 78E298841A0D0071007953FB /* Products */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 78E298831A0D0071007953FB /* PSTAlertViewControllerSample.app */, 64 | ); 65 | name = Products; 66 | sourceTree = ""; 67 | }; 68 | 78E298851A0D0071007953FB /* PSTAlertViewControllerSample */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 78E298AF1A0D0B25007953FB /* PSTAlertController */, 72 | 78E2988A1A0D0071007953FB /* AppDelegate.h */, 73 | 78E2988B1A0D0071007953FB /* AppDelegate.m */, 74 | 78E2988D1A0D0071007953FB /* ViewController.h */, 75 | 78E2988E1A0D0071007953FB /* ViewController.m */, 76 | 78E298901A0D0071007953FB /* Main.storyboard */, 77 | 78E298931A0D0071007953FB /* Images.xcassets */, 78 | 78E298951A0D0071007953FB /* LaunchScreen.xib */, 79 | 78E298861A0D0071007953FB /* Supporting Files */, 80 | ); 81 | path = PSTAlertViewControllerSample; 82 | sourceTree = ""; 83 | }; 84 | 78E298861A0D0071007953FB /* Supporting Files */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 78E298871A0D0071007953FB /* Info.plist */, 88 | 78E298881A0D0071007953FB /* main.m */, 89 | ); 90 | name = "Supporting Files"; 91 | sourceTree = ""; 92 | }; 93 | 78E2989F1A0D0071007953FB /* PSTAlertViewControllerSampleTests */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 78E298A21A0D0071007953FB /* PSTAlertViewControllerSampleTests.m */, 97 | 78E298A01A0D0071007953FB /* Supporting Files */, 98 | ); 99 | path = PSTAlertViewControllerSampleTests; 100 | sourceTree = ""; 101 | }; 102 | 78E298A01A0D0071007953FB /* Supporting Files */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | 78E298A11A0D0071007953FB /* Info.plist */, 106 | ); 107 | name = "Supporting Files"; 108 | sourceTree = ""; 109 | }; 110 | 78E298AF1A0D0B25007953FB /* PSTAlertController */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 78E298B01A0D0B25007953FB /* PSTAlertController.h */, 114 | 78E298B11A0D0B25007953FB /* PSTAlertController.m */, 115 | ); 116 | name = PSTAlertController; 117 | path = ../../PSTAlertController; 118 | sourceTree = ""; 119 | }; 120 | /* End PBXGroup section */ 121 | 122 | /* Begin PBXNativeTarget section */ 123 | 78E298821A0D0071007953FB /* PSTAlertViewControllerSample */ = { 124 | isa = PBXNativeTarget; 125 | buildConfigurationList = 78E298A61A0D0071007953FB /* Build configuration list for PBXNativeTarget "PSTAlertViewControllerSample" */; 126 | buildPhases = ( 127 | 78E2987F1A0D0071007953FB /* Sources */, 128 | 78E298801A0D0071007953FB /* Frameworks */, 129 | 78E298811A0D0071007953FB /* Resources */, 130 | ); 131 | buildRules = ( 132 | ); 133 | dependencies = ( 134 | ); 135 | name = PSTAlertViewControllerSample; 136 | productName = PSTAlertViewControllerSample; 137 | productReference = 78E298831A0D0071007953FB /* PSTAlertViewControllerSample.app */; 138 | productType = "com.apple.product-type.application"; 139 | }; 140 | /* End PBXNativeTarget section */ 141 | 142 | /* Begin PBXProject section */ 143 | 78E2987B1A0D0071007953FB /* Project object */ = { 144 | isa = PBXProject; 145 | attributes = { 146 | LastUpgradeCheck = 0610; 147 | ORGANIZATIONNAME = "PSPDFKit GmbH"; 148 | TargetAttributes = { 149 | 78E298821A0D0071007953FB = { 150 | CreatedOnToolsVersion = 6.1; 151 | }; 152 | }; 153 | }; 154 | buildConfigurationList = 78E2987E1A0D0071007953FB /* Build configuration list for PBXProject "PSTAlertViewControllerSample" */; 155 | compatibilityVersion = "Xcode 3.2"; 156 | developmentRegion = English; 157 | hasScannedForEncodings = 0; 158 | knownRegions = ( 159 | en, 160 | Base, 161 | ); 162 | mainGroup = 78E2987A1A0D0071007953FB; 163 | productRefGroup = 78E298841A0D0071007953FB /* Products */; 164 | projectDirPath = ""; 165 | projectRoot = ""; 166 | targets = ( 167 | 78E298821A0D0071007953FB /* PSTAlertViewControllerSample */, 168 | ); 169 | }; 170 | /* End PBXProject section */ 171 | 172 | /* Begin PBXResourcesBuildPhase section */ 173 | 78E298811A0D0071007953FB /* Resources */ = { 174 | isa = PBXResourcesBuildPhase; 175 | buildActionMask = 2147483647; 176 | files = ( 177 | 78E298921A0D0071007953FB /* Main.storyboard in Resources */, 178 | 78E298971A0D0071007953FB /* LaunchScreen.xib in Resources */, 179 | 78E298941A0D0071007953FB /* Images.xcassets in Resources */, 180 | ); 181 | runOnlyForDeploymentPostprocessing = 0; 182 | }; 183 | /* End PBXResourcesBuildPhase section */ 184 | 185 | /* Begin PBXSourcesBuildPhase section */ 186 | 78E2987F1A0D0071007953FB /* Sources */ = { 187 | isa = PBXSourcesBuildPhase; 188 | buildActionMask = 2147483647; 189 | files = ( 190 | 78E2988F1A0D0071007953FB /* ViewController.m in Sources */, 191 | 78E2988C1A0D0071007953FB /* AppDelegate.m in Sources */, 192 | 78E298B21A0D0B25007953FB /* PSTAlertController.m in Sources */, 193 | 78E298891A0D0071007953FB /* main.m in Sources */, 194 | ); 195 | runOnlyForDeploymentPostprocessing = 0; 196 | }; 197 | /* End PBXSourcesBuildPhase section */ 198 | 199 | /* Begin PBXVariantGroup section */ 200 | 78E298901A0D0071007953FB /* Main.storyboard */ = { 201 | isa = PBXVariantGroup; 202 | children = ( 203 | 78E298911A0D0071007953FB /* Base */, 204 | ); 205 | name = Main.storyboard; 206 | sourceTree = ""; 207 | }; 208 | 78E298951A0D0071007953FB /* LaunchScreen.xib */ = { 209 | isa = PBXVariantGroup; 210 | children = ( 211 | 78E298961A0D0071007953FB /* Base */, 212 | ); 213 | name = LaunchScreen.xib; 214 | sourceTree = ""; 215 | }; 216 | /* End PBXVariantGroup section */ 217 | 218 | /* Begin XCBuildConfiguration section */ 219 | 78E298A41A0D0071007953FB /* Debug */ = { 220 | isa = XCBuildConfiguration; 221 | buildSettings = { 222 | ALWAYS_SEARCH_USER_PATHS = NO; 223 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 224 | CLANG_CXX_LIBRARY = "libc++"; 225 | CLANG_ENABLE_MODULES = YES; 226 | CLANG_ENABLE_OBJC_ARC = YES; 227 | CLANG_WARN_BOOL_CONVERSION = YES; 228 | CLANG_WARN_CONSTANT_CONVERSION = YES; 229 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 230 | CLANG_WARN_EMPTY_BODY = YES; 231 | CLANG_WARN_ENUM_CONVERSION = YES; 232 | CLANG_WARN_INT_CONVERSION = YES; 233 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 234 | CLANG_WARN_UNREACHABLE_CODE = YES; 235 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 236 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 237 | COPY_PHASE_STRIP = NO; 238 | ENABLE_STRICT_OBJC_MSGSEND = YES; 239 | GCC_C_LANGUAGE_STANDARD = gnu99; 240 | GCC_DYNAMIC_NO_PIC = NO; 241 | GCC_OPTIMIZATION_LEVEL = 0; 242 | GCC_PREPROCESSOR_DEFINITIONS = ( 243 | "DEBUG=1", 244 | "$(inherited)", 245 | ); 246 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 247 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 248 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 249 | GCC_WARN_UNDECLARED_SELECTOR = YES; 250 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 251 | GCC_WARN_UNUSED_FUNCTION = YES; 252 | GCC_WARN_UNUSED_VARIABLE = YES; 253 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 254 | MTL_ENABLE_DEBUG_INFO = YES; 255 | ONLY_ACTIVE_ARCH = YES; 256 | SDKROOT = iphoneos; 257 | TARGETED_DEVICE_FAMILY = "1,2"; 258 | }; 259 | name = Debug; 260 | }; 261 | 78E298A51A0D0071007953FB /* Release */ = { 262 | isa = XCBuildConfiguration; 263 | buildSettings = { 264 | ALWAYS_SEARCH_USER_PATHS = NO; 265 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 266 | CLANG_CXX_LIBRARY = "libc++"; 267 | CLANG_ENABLE_MODULES = YES; 268 | CLANG_ENABLE_OBJC_ARC = YES; 269 | CLANG_WARN_BOOL_CONVERSION = YES; 270 | CLANG_WARN_CONSTANT_CONVERSION = YES; 271 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 272 | CLANG_WARN_EMPTY_BODY = YES; 273 | CLANG_WARN_ENUM_CONVERSION = YES; 274 | CLANG_WARN_INT_CONVERSION = YES; 275 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 276 | CLANG_WARN_UNREACHABLE_CODE = YES; 277 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 278 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 279 | COPY_PHASE_STRIP = YES; 280 | ENABLE_NS_ASSERTIONS = NO; 281 | ENABLE_STRICT_OBJC_MSGSEND = YES; 282 | GCC_C_LANGUAGE_STANDARD = gnu99; 283 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 284 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 285 | GCC_WARN_UNDECLARED_SELECTOR = YES; 286 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 287 | GCC_WARN_UNUSED_FUNCTION = YES; 288 | GCC_WARN_UNUSED_VARIABLE = YES; 289 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 290 | MTL_ENABLE_DEBUG_INFO = NO; 291 | SDKROOT = iphoneos; 292 | TARGETED_DEVICE_FAMILY = "1,2"; 293 | VALIDATE_PRODUCT = YES; 294 | }; 295 | name = Release; 296 | }; 297 | 78E298A71A0D0071007953FB /* Debug */ = { 298 | isa = XCBuildConfiguration; 299 | buildSettings = { 300 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 301 | INFOPLIST_FILE = PSTAlertViewControllerSample/Info.plist; 302 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 303 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 304 | PRODUCT_NAME = "$(TARGET_NAME)"; 305 | }; 306 | name = Debug; 307 | }; 308 | 78E298A81A0D0071007953FB /* Release */ = { 309 | isa = XCBuildConfiguration; 310 | buildSettings = { 311 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 312 | INFOPLIST_FILE = PSTAlertViewControllerSample/Info.plist; 313 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 314 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 315 | PRODUCT_NAME = "$(TARGET_NAME)"; 316 | }; 317 | name = Release; 318 | }; 319 | /* End XCBuildConfiguration section */ 320 | 321 | /* Begin XCConfigurationList section */ 322 | 78E2987E1A0D0071007953FB /* Build configuration list for PBXProject "PSTAlertViewControllerSample" */ = { 323 | isa = XCConfigurationList; 324 | buildConfigurations = ( 325 | 78E298A41A0D0071007953FB /* Debug */, 326 | 78E298A51A0D0071007953FB /* Release */, 327 | ); 328 | defaultConfigurationIsVisible = 0; 329 | defaultConfigurationName = Release; 330 | }; 331 | 78E298A61A0D0071007953FB /* Build configuration list for PBXNativeTarget "PSTAlertViewControllerSample" */ = { 332 | isa = XCConfigurationList; 333 | buildConfigurations = ( 334 | 78E298A71A0D0071007953FB /* Debug */, 335 | 78E298A81A0D0071007953FB /* Release */, 336 | ); 337 | defaultConfigurationIsVisible = 0; 338 | defaultConfigurationName = Release; 339 | }; 340 | /* End XCConfigurationList section */ 341 | }; 342 | rootObject = 78E2987B1A0D0071007953FB /* Project object */; 343 | } 344 | -------------------------------------------------------------------------------- /Example/PSTAlertViewControllerSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/PSTAlertViewControllerSample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // PSTAlertViewControllerSample 4 | // 5 | // Created by Peter Steinberger on 07/11/14. 6 | // Copyright (c) 2014 PSPDFKit GmbH. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /Example/PSTAlertViewControllerSample/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // PSTAlertViewControllerSample 4 | // 5 | // Created by Peter Steinberger on 07/11/14. 6 | // Copyright (c) 2014 PSPDFKit GmbH. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @implementation AppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 14 | // Override point for customization after application launch. 15 | return YES; 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Example/PSTAlertViewControllerSample/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Example/PSTAlertViewControllerSample/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 33 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Example/PSTAlertViewControllerSample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Example/PSTAlertViewControllerSample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.pspdfkit.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Example/PSTAlertViewControllerSample/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // PSTAlertViewControllerSample 4 | // 5 | // Created by Peter Steinberger on 07/11/14. 6 | // Copyright (c) 2014 PSPDFKit GmbH. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | @end 14 | 15 | -------------------------------------------------------------------------------- /Example/PSTAlertViewControllerSample/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // PSTAlertViewControllerSample 4 | // 5 | // Created by Peter Steinberger on 07/11/14. 6 | // Copyright (c) 2014 PSPDFKit GmbH. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "PSTAlertController.h" 11 | 12 | @implementation ViewController 13 | 14 | - (void)viewDidAppear:(BOOL)animated { 15 | [super viewDidAppear:animated]; 16 | } 17 | 18 | - (IBAction)testButtonPressed:(UIButton *)sender { 19 | PSTAlertController *controller = [PSTAlertController actionSheetWithTitle:nil]; 20 | [controller addAction:[PSTAlertAction actionWithTitle:@"OK" style:PSTAlertActionStyleDestructive handler:nil]]; 21 | // Cancel action on a sheet should be the last action. 22 | [controller addCancelActionWithHandler:nil]; 23 | [controller showWithSender:sender arrowDirection:UIPopoverArrowDirectionAny controller:self animated:YES completion:nil]; 24 | } 25 | 26 | - (IBAction)doTheDance:(UIButton *)sender { 27 | PSTAlertController *gotoPageController = [PSTAlertController alertWithTitle:@"Go to page" message:nil]; 28 | [gotoPageController addTextFieldWithConfigurationHandler:^(UITextField *textField) { 29 | textField.keyboardType = UIKeyboardTypeNumberPad; 30 | }]; 31 | [gotoPageController addCancelActionWithHandler:NULL]; 32 | [gotoPageController addAction:[PSTAlertAction actionWithTitle:@"Go to" handler:^(PSTAlertAction *action) { 33 | NSString *pageLabel = action.alertController.textField.text; 34 | PSTAlertController *dismissable = [PSTAlertController presentDismissableAlertWithTitle:@"Result" message:[NSString stringWithFormat:@"You entered %@", pageLabel] controller:self]; 35 | [dismissable addDidDismissBlock:^(PSTAlertAction *action) { 36 | [self doTheDance:nil]; 37 | }]; 38 | }]]; 39 | [gotoPageController addAction:[PSTAlertAction actionWithTitle:@"No" style:PSTAlertActionStyleDestructive handler:^(PSTAlertAction *action) { 40 | PSTAlertController *sheetController = [PSTAlertController actionSheetWithTitle:@"No?"]; 41 | [sheetController addAction:[PSTAlertAction actionWithTitle:@"I've changed my mind" handler:^(PSTAlertAction *action) { 42 | [self doTheDance:nil]; 43 | }]]; 44 | // Cancel action on a sheet should be the last action. 45 | [sheetController addAction:[PSTAlertAction actionWithTitle:@"That's fine." style:PSTAlertActionStyleCancel handler:NULL]]; 46 | [sheetController showWithSender:[NSValue valueWithCGRect:CGRectMake(100.f, 100.f, 1.f, 1.f)] controller:self animated:YES completion:^{ 47 | NSLog(@"Okay, let's do that again..."); 48 | }]; 49 | }]]; 50 | [gotoPageController showWithSender:nil controller:self animated:YES completion:NULL]; 51 | } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /Example/PSTAlertViewControllerSample/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // PSTAlertViewControllerSample 4 | // 5 | // Created by Peter Steinberger on 07/11/14. 6 | // Copyright (c) 2014 PSPDFKit GmbH. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Peter Steinberger 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /PSTAlertController.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod lib lint PSTAlertController.podspec' to ensure this is a 3 | # valid spec and remove all comments before submitting the spec. 4 | # 5 | # Any lines starting with a # are optional, but encouraged 6 | # 7 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html 8 | # 9 | 10 | Pod::Spec.new do |s| 11 | s.name = "PSTAlertController" 12 | s.version = "1.2.0" 13 | s.summary = "API similar to UIAlertController, backwards compatible to iOS 7. Will use the new shiny API when you run iOS 8. " 14 | s.description = <<-DESC 15 | We cheat a bit by having PSTAlertController superclass be NSObject, but for most use cases it's still a lot more convenient than using UIAlertView/UIActionSheet. 16 | DESC 17 | s.homepage = "https://github.com/steipete/PSTAlertController" 18 | s.license = 'MIT' 19 | s.author = { "Peter Steinberger" => "steipete@gmail.com" } 20 | s.source = { :git => "https://github.com/steipete/PSTAlertController.git", :tag => s.version.to_s } 21 | # s.social_media_url = 'https://twitter.com/steipete' 22 | 23 | s.platform = :ios, '7.0' 24 | s.requires_arc = true 25 | 26 | s.source_files = 'PSTAlertController' 27 | s.public_header_files = 'PSTAlertController/**/*.h' 28 | s.frameworks = 'UIKit' 29 | end -------------------------------------------------------------------------------- /PSTAlertController/PSTAlertController.h: -------------------------------------------------------------------------------- 1 | // 2 | // PSTAlertController.h 3 | // 4 | // Licensed under the MIT license. 5 | // Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | // SOFTWARE. 24 | // 25 | 26 | #import 27 | #import 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | typedef NS_ENUM(NSInteger, PSTAlertControllerStyle) { 32 | PSTAlertControllerStyleActionSheet = 0, 33 | PSTAlertControllerStyleAlert 34 | }; 35 | 36 | typedef NS_ENUM(NSInteger, PSTAlertActionStyle) { 37 | PSTAlertActionStyleDefault = 0, 38 | PSTAlertActionStyleCancel, 39 | PSTAlertActionStyleDestructive 40 | }; 41 | 42 | @class PSTAlertController; 43 | 44 | // Defines a single button/action. 45 | @interface PSTAlertAction : NSObject 46 | + (instancetype)actionWithTitle:(NSString *)title style:(PSTAlertActionStyle)style handler:(void (^ __nullable)(PSTAlertAction *action))handler; 47 | + (instancetype)actionWithTitle:(NSString *)title handler:(void (^ __nullable)(PSTAlertAction *action))handler; 48 | @property (nonatomic, readonly) PSTAlertActionStyle style; 49 | 50 | @property (nonatomic, weak) PSTAlertController *alertController; // weak connection 51 | 52 | @end 53 | 54 | // Mashup of UIAlertController with fallback methods for iOS 7. 55 | // @note Blocks are generally executed after the dismiss animation is completed. 56 | @interface PSTAlertController : NSObject 57 | 58 | // Generic initializer 59 | + (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(PSTAlertControllerStyle)preferredStyle; 60 | - (instancetype)init NS_UNAVAILABLE; 61 | 62 | // Add action. 63 | - (void)addAction:(PSTAlertAction *)action; 64 | 65 | // Add block that is called after the alert controller will be dismissed (before animation). 66 | - (void)addWillDismissBlock:(void (^)(PSTAlertAction *action))willDismissBlock; 67 | 68 | // Add block that is called after the alert view has been dismissed (after animation). 69 | - (void)addDidDismissBlock:(void (^)(PSTAlertAction *action))didDismissBlock; 70 | 71 | @property (nullable, nonatomic, copy, readonly) NSArray *actions; 72 | 73 | // Text field support 74 | - (void)addTextFieldWithConfigurationHandler:(void (^ __nullable)(UITextField *textField))configurationHandler; 75 | @property (nullable, nonatomic, readonly) NSArray *textFields; 76 | 77 | @property (nullable, nonatomic, copy) NSString *title; 78 | @property (nullable, nonatomic, copy) NSString *message; 79 | 80 | @property (nonatomic, readonly) PSTAlertControllerStyle preferredStyle; 81 | 82 | // Presentation and dismissal 83 | - (void)showWithSender:(nullable id)sender controller:(nullable UIViewController *)controller animated:(BOOL)animated completion:(void (^ __nullable)(void))completion; 84 | - (void)showWithSender:(nullable id)sender arrowDirection:(UIPopoverArrowDirection)arrowDirection controller:(nullable UIViewController *)controller animated:(BOOL)animated completion:(void (^ __nullable)(void))completion; 85 | - (void)dismissAnimated:(BOOL)animated completion:(void (^ __nullable)(void))completion; 86 | 87 | + (BOOL)hasVisibleAlertController; 88 | @property (nonatomic, readonly, getter=isVisible) BOOL visible; 89 | 90 | @end 91 | 92 | @interface PSTAlertController (Convenience) 93 | 94 | // Convenience initializers 95 | + (instancetype)actionSheetWithTitle:(nullable NSString *)title; 96 | + (instancetype)alertWithTitle:(nullable NSString *)title message:(nullable NSString *)message; 97 | 98 | // Convenience. Presents a simple alert with a "Dismiss" button. 99 | // Will use the root view controller if `controller` is nil. 100 | + (instancetype)presentDismissableAlertWithTitle:(nullable NSString *)title message:(nullable NSString *)message controller:(nullable UIViewController *)controller; 101 | 102 | // Variant that will present an error. 103 | + (instancetype)presentDismissableAlertWithTitle:(nullable NSString *)title error:(nullable NSError *)error controller:(nullable UIViewController *)controller; 104 | 105 | // From Apple's HIG: 106 | // In a two-button alert that proposes a potentially risky action, the button that cancels the action should be on the right (and light-colored). 107 | // In a two-button alert that proposes a benign action that people are likely to want, the button that cancels the action should be on the left (and dark-colored). 108 | - (void)addCancelActionWithHandler:(void (^ __nullable)(PSTAlertAction *action))handler; // convenience 109 | 110 | @property (nullable, nonatomic, readonly) UITextField *textField; 111 | 112 | @end 113 | 114 | 115 | @interface PSTAlertController (Internal) 116 | 117 | @property (nullable, nonatomic, strong, readonly) UIAlertController *alertController; 118 | 119 | @property (nullable, nonatomic, strong, readonly) UIActionSheet *actionSheet; 120 | @property (nullable, nonatomic, strong, readonly) UIAlertView *alertView; 121 | 122 | // One if the above three. 123 | @property (nullable, nonatomic, strong, readonly) id presentedObject; 124 | 125 | @end 126 | 127 | NS_ASSUME_NONNULL_END 128 | -------------------------------------------------------------------------------- /PSTAlertController/PSTAlertController.m: -------------------------------------------------------------------------------- 1 | // 2 | // PSTAlertController.m 3 | // 4 | // Copyright (c) 2014 PSPDFKit GmbH. All rights reserved. 5 | // 6 | 7 | #import "PSTAlertController.h" 8 | #import 9 | 10 | #define PROPERTY(property) NSStringFromSelector(@selector(property)) 11 | 12 | @interface PSTAlertAction () 13 | @property (nonatomic, copy) NSString *title; 14 | @property (nonatomic, assign) PSTAlertActionStyle style; 15 | @property (nonatomic, copy) void (^handler)(PSTAlertAction *action); 16 | - (void)performAction; 17 | @end 18 | 19 | @implementation PSTAlertAction 20 | 21 | + (instancetype)actionWithTitle:(NSString *)title style:(PSTAlertActionStyle)style handler:(void (^)(PSTAlertAction *action))handler { 22 | return [[self alloc] initWithTitle:title style:style handler:handler]; 23 | } 24 | 25 | + (instancetype)actionWithTitle:(NSString *)title handler:(void (^)(PSTAlertAction *action))handler { 26 | return [[self alloc] initWithTitle:title style:PSTAlertActionStyleDefault handler:handler]; 27 | } 28 | 29 | - (instancetype)initWithTitle:(NSString *)title style:(PSTAlertActionStyle)style handler:(void (^)(PSTAlertAction *action))handler { 30 | if ((self = [super init])) { 31 | _title = [title copy]; 32 | _style = style; 33 | _handler = [handler copy]; 34 | } 35 | return self; 36 | } 37 | 38 | - (void)performAction { 39 | if (self.handler) { 40 | self.handler(self); 41 | self.handler = nil; // nil out after calling to break cycles. 42 | } 43 | } 44 | 45 | @end 46 | 47 | @interface PSTExtendedAlertController : UIAlertController 48 | @property (nonatomic, copy) void (^viewWillDisappearBlock)(void); 49 | @property (nonatomic, copy) void (^viewDidDisappearBlock)(void); 50 | @end 51 | 52 | @implementation PSTExtendedAlertController 53 | 54 | - (void)viewWillDisappear:(BOOL)animated { 55 | [super viewWillDisappear:animated]; 56 | if (self.viewWillDisappearBlock) self.viewWillDisappearBlock(); 57 | } 58 | 59 | - (void)viewDidDisappear:(BOOL)animated { 60 | [super viewDidDisappear:animated]; 61 | if (self.viewDidDisappearBlock) self.viewDidDisappearBlock(); 62 | } 63 | 64 | @end 65 | 66 | @interface PSTAlertController () { 67 | struct { 68 | unsigned int isShowingAlert:1; 69 | } _flags; 70 | } 71 | - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(PSTAlertControllerStyle)preferredStyle NS_DESIGNATED_INITIALIZER; 72 | 73 | @property (nonatomic, copy) NSArray *willDismissBlocks; 74 | @property (nonatomic, copy) NSArray *didDismissBlocks; 75 | 76 | // iOS 8 77 | @property (nonatomic, strong) PSTExtendedAlertController *alertController; 78 | 79 | // Universal 80 | @property (nonatomic, weak) PSTAlertAction *executedAlertAction; 81 | 82 | // iOS 7 83 | @property (nonatomic, copy) NSArray *actions; 84 | @property (nonatomic, copy) NSArray *textFieldHandlers; 85 | @property (nonatomic, strong, readonly) UIActionSheet *actionSheet; 86 | @property (nonatomic, strong, readonly) UIAlertView *alertView; 87 | 88 | // Storage for actionSheet/alertView 89 | @property (nonatomic, strong) UIView *strongSheetStorage; 90 | @property (nonatomic, weak) UIView *weakSheetStorage; 91 | @end 92 | 93 | @implementation PSTAlertController 94 | 95 | /////////////////////////////////////////////////////////////////////////////////////////// 96 | #pragma mark - Initialization 97 | 98 | - (BOOL)alertControllerAvailable { 99 | return [UIAlertController class] != nil; // iOS 8 and later. 100 | } 101 | 102 | + (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(PSTAlertControllerStyle)preferredStyle { 103 | return [[self alloc] initWithTitle:title message:message preferredStyle:preferredStyle]; 104 | } 105 | 106 | - (instancetype)init NS_UNAVAILABLE { 107 | assert(0); 108 | } 109 | 110 | - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(PSTAlertControllerStyle)preferredStyle { 111 | if ((self = [super init])) { 112 | _title = [title copy]; 113 | _message = [message copy]; 114 | _preferredStyle = preferredStyle; 115 | 116 | if ([self alertControllerAvailable]) { 117 | _alertController = [PSTExtendedAlertController alertControllerWithTitle:title message:message preferredStyle:(UIAlertControllerStyle)preferredStyle]; 118 | } else { 119 | #if __IPHONE_OS_VERSION_MIN_REQUIRED < 80000 120 | if (preferredStyle == PSTAlertControllerStyleActionSheet) { 121 | NSString *titleAndMessage = title; 122 | if (title && message) { 123 | titleAndMessage = [NSString stringWithFormat:@"%@\n%@", title, message]; 124 | } 125 | _strongSheetStorage = [[UIActionSheet alloc] initWithTitle:titleAndMessage delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; 126 | } else { 127 | _strongSheetStorage = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:nil otherButtonTitles:nil]; 128 | } 129 | #endif 130 | } 131 | } 132 | return self; 133 | } 134 | 135 | - (NSString *)description { 136 | return [NSString stringWithFormat:@"<%@: %p, title:%@, actions:%@>", NSStringFromClass(self.class), self, self.title, self.actions]; 137 | } 138 | 139 | - (void)setTitle:(NSString *)title { 140 | _title = [title copy]; 141 | _alertController.title = title; 142 | 143 | id obj = self.strongSheetStorage ?: self.weakSheetStorage; 144 | if ([obj respondsToSelector:@selector(setTitle:)]) { 145 | [obj setTitle:title]; 146 | } 147 | } 148 | 149 | - (void)setMessage:(NSString *)message { 150 | _message = [message copy]; 151 | _alertController.message = message; 152 | 153 | id obj = self.strongSheetStorage ?: self.weakSheetStorage; 154 | if ([obj respondsToSelector:@selector(setMessage:)]) { 155 | [obj setMessage:message]; 156 | } else if ([obj respondsToSelector:@selector(setTitle:)]) { 157 | NSString *final = message; 158 | if (_title && message) { 159 | final = [NSString stringWithFormat:@"%@\n%@", _title, message]; 160 | } 161 | [obj setTitle:final]; 162 | } 163 | } 164 | 165 | - (void)dealloc { 166 | // In case the alert controller can't be displayed for any reason, 167 | // We'd still increment the counter and need to do the cleanup work here. 168 | [self setIsShowingAlert:NO]; 169 | } 170 | 171 | /////////////////////////////////////////////////////////////////////////////////////////// 172 | #pragma mark - Accessors 173 | 174 | - (UIAlertView *)alertView { 175 | return (UIAlertView *)(self.strongSheetStorage ?: self.weakSheetStorage); 176 | } 177 | 178 | - (UIActionSheet *)actionSheet { 179 | return (UIActionSheet *)(self.strongSheetStorage ?: self.weakSheetStorage); 180 | } 181 | 182 | /////////////////////////////////////////////////////////////////////////////////////////// 183 | #pragma mark - Adding Actions 184 | 185 | - (void)addAction:(PSTAlertAction *)action { 186 | NSAssert([action isKindOfClass:PSTAlertAction.class], @"Must be of type PSTAlertAction"); 187 | 188 | action.alertController = self; // weakly connect 189 | 190 | self.actions = [[NSArray arrayWithArray:self.actions] arrayByAddingObject:action]; 191 | 192 | if ([self alertControllerAvailable]) { 193 | __weak typeof (self) weakSelf = self; 194 | UIAlertAction *alertAction = [UIAlertAction actionWithTitle:action.title style:(UIAlertActionStyle)action.style handler:^(UIAlertAction *uiAction) { 195 | weakSelf.executedAlertAction = action; 196 | [action performAction]; 197 | }]; 198 | [self.alertController addAction:alertAction]; 199 | } else { 200 | if (self.preferredStyle == PSTAlertControllerStyleActionSheet) { 201 | NSUInteger currentButtonIndex = [self.actionSheet addButtonWithTitle:action.title]; 202 | 203 | if (action.style == PSTAlertActionStyleDestructive) { 204 | self.actionSheet.destructiveButtonIndex = currentButtonIndex; 205 | } else if (action.style == PSTAlertActionStyleCancel) { 206 | self.actionSheet.cancelButtonIndex = currentButtonIndex; 207 | } 208 | } else { 209 | NSUInteger currentButtonIndex = [self.alertView addButtonWithTitle:action.title]; 210 | 211 | // UIAlertView doesn't support destructive buttons. 212 | if (action.style == PSTAlertActionStyleCancel) { 213 | self.alertView.cancelButtonIndex = currentButtonIndex; 214 | } 215 | } 216 | } 217 | } 218 | 219 | /////////////////////////////////////////////////////////////////////////////////////////// 220 | #pragma mark - Text Field Support 221 | 222 | - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler { 223 | if ([self alertControllerAvailable]) { 224 | [self.alertController addTextFieldWithConfigurationHandler:configurationHandler]; 225 | } else { 226 | NSAssert(self.preferredStyle == PSTAlertControllerStyleAlert, @"Text fields are only supported for alerts."); 227 | self.textFieldHandlers = [[NSArray arrayWithArray:self.textFieldHandlers] arrayByAddingObject:configurationHandler ?: ^(UITextField *textField){}]; 228 | self.alertView.alertViewStyle = self.textFieldHandlers.count > 1 ? UIAlertViewStyleLoginAndPasswordInput : UIAlertViewStylePlainTextInput; 229 | } 230 | } 231 | 232 | - (NSArray *)textFields { 233 | if ([self alertControllerAvailable]) { 234 | return self.alertController.textFields; 235 | } else if (self.preferredStyle == PSTAlertControllerStyleAlert) { 236 | switch (self.alertView.alertViewStyle) { 237 | case UIAlertViewStyleSecureTextInput: 238 | case UIAlertViewStylePlainTextInput: 239 | return @[[self.alertView textFieldAtIndex:0]]; 240 | case UIAlertViewStyleLoginAndPasswordInput: 241 | return @[[self.alertView textFieldAtIndex:0], [self.alertView textFieldAtIndex:1]]; 242 | case UIAlertViewStyleDefault: 243 | return @[]; 244 | } 245 | } 246 | // UIActionSheet doesn't support text fields. 247 | return nil; 248 | } 249 | 250 | - (UITextField *)textField { 251 | return self.textFields.firstObject; 252 | } 253 | 254 | /////////////////////////////////////////////////////////////////////////////////////////// 255 | #pragma mark - Presentation 256 | 257 | static NSUInteger PSTVisibleAlertsCount = 0; 258 | + (BOOL)hasVisibleAlertController { 259 | return PSTVisibleAlertsCount > 0; 260 | } 261 | 262 | - (BOOL)isVisible { 263 | if ([self alertControllerAvailable]) { 264 | return self.alertController.view.window != nil; 265 | } else { 266 | if (self.preferredStyle == PSTAlertControllerStyleActionSheet) { 267 | return self.actionSheet.isVisible; 268 | } else { 269 | return self.alertView.isVisible; 270 | } 271 | } 272 | } 273 | 274 | - (void)showWithSender:(id)sender controller:(UIViewController *)controller animated:(BOOL)animated completion:(void (^)(void))completion { 275 | [self showWithSender:sender arrowDirection:UIPopoverArrowDirectionAny controller:controller animated:animated completion:completion]; 276 | } 277 | 278 | - (void)showWithSender:(id)sender arrowDirection:(UIPopoverArrowDirection)arrowDirection controller:(UIViewController *)controller animated:(BOOL)animated completion:(void (^)(void))completion { 279 | if ([self alertControllerAvailable]) { 280 | // As a convenience, allow automatic root view controller fetching if we show an alert. 281 | if (self.preferredStyle == PSTAlertControllerStyleAlert) { 282 | if (!controller) { 283 | // sharedApplication is unavailable for extensions, but required for things like preferredContentSizeCategory. 284 | UIApplication *sharedApplication = [UIApplication performSelector:NSSelectorFromString(PROPERTY(sharedApplication))]; 285 | controller = sharedApplication.keyWindow.rootViewController; 286 | } 287 | 288 | // Use the frontmost viewController for presentation. 289 | while (controller.presentedViewController) { 290 | controller = controller.presentedViewController; 291 | } 292 | 293 | if (!controller) { 294 | NSLog(@"Can't show alert because there is no root view controller."); 295 | return; 296 | } 297 | } 298 | 299 | // We absolutely need a controller going forward. 300 | NSParameterAssert(controller); 301 | 302 | PSTExtendedAlertController *alertController = self.alertController; 303 | UIPopoverPresentationController *popoverPresentation = alertController.popoverPresentationController; 304 | if (popoverPresentation) { // nil on iPhone 305 | if ([sender isKindOfClass:UIBarButtonItem.class]) { 306 | popoverPresentation.barButtonItem = sender; 307 | } else if ([sender isKindOfClass:UIView.class]) { 308 | popoverPresentation.sourceView = sender; 309 | popoverPresentation.sourceRect = [sender bounds]; 310 | } else if ([sender isKindOfClass:NSValue.class]) { 311 | popoverPresentation.sourceView = controller.view; 312 | popoverPresentation.sourceRect = [sender CGRectValue]; 313 | } else { 314 | popoverPresentation.sourceView = controller.view; 315 | popoverPresentation.sourceRect = controller.view.bounds; 316 | } 317 | 318 | // Workaround for rdar://18921595. Unsatisfiable constraints when presenting UIAlertController. 319 | // If the rect is too large, the action sheet can't be displayed. 320 | CGRect r = popoverPresentation.sourceRect, screen = UIScreen.mainScreen.bounds; 321 | if (CGRectGetHeight(r) > CGRectGetHeight(screen)*0.5 || CGRectGetWidth(r) > CGRectGetWidth(screen)*0.5) { 322 | popoverPresentation.sourceRect = CGRectMake(r.origin.x + r.size.width/2.f, r.origin.y + r.size.height/2.f, 1.f, 1.f); 323 | } 324 | 325 | // optimize arrow positioning for up and down. 326 | popoverPresentation.permittedArrowDirections = arrowDirection; 327 | switch (arrowDirection) { 328 | case UIPopoverArrowDirectionDown: 329 | popoverPresentation.sourceRect = CGRectMake(r.origin.x + r.size.width/2.f, r.origin.y, 1.f, 1.f); 330 | break; 331 | case UIPopoverArrowDirectionUp: 332 | popoverPresentation.sourceRect = CGRectMake(r.origin.x + r.size.width/2.f, r.origin.y + r.size.height, 1.f, 1.f); 333 | break; 334 | // Left and right is too buggy. 335 | default: 336 | break; 337 | } 338 | } 339 | 340 | // Hook up dismiss blocks. 341 | __weak typeof (self) weakSelf = self; 342 | alertController.viewWillDisappearBlock = ^{ 343 | typeof (self) strongSelf = weakSelf; 344 | [strongSelf performBlocks:PROPERTY(willDismissBlocks) withAction:strongSelf.executedAlertAction]; 345 | [strongSelf setIsShowingAlert:NO]; 346 | }; 347 | alertController.viewDidDisappearBlock = ^{ 348 | typeof (self) strongSelf = weakSelf; 349 | [strongSelf performBlocks:PROPERTY(didDismissBlocks) withAction:strongSelf.executedAlertAction]; 350 | }; 351 | 352 | [controller presentViewController:alertController animated:animated completion:^{ 353 | // Bild lifetime of self to the controller. 354 | // Will not be called if presenting fails because another present/dismissal already happened during that runloop. 355 | // rdar://problem/19045528 356 | objc_setAssociatedObject(controller, _cmd, self, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 357 | }]; 358 | 359 | } else { 360 | if (self.preferredStyle == PSTAlertControllerStyleActionSheet) { 361 | [self showActionSheetWithSender:sender fallbackView:controller.view animated:animated]; 362 | [self moveSheetToWeakStorage]; 363 | } else { 364 | // Call text field configuration handlers. 365 | [self.textFieldHandlers enumerateObjectsUsingBlock:^(void (^configurationHandler)(UITextField *textField), NSUInteger idx, BOOL *stop) { 366 | configurationHandler([self.alertView textFieldAtIndex:idx]); 367 | }]; 368 | [self.alertView show]; 369 | [self moveSheetToWeakStorage]; 370 | } 371 | // This is called before the animation is complete, but at least it's called. 372 | if (completion) completion(); 373 | } 374 | [self setIsShowingAlert:YES]; 375 | } 376 | 377 | - (void)setIsShowingAlert:(BOOL)isShowing { 378 | if (_flags.isShowingAlert != isShowing) { 379 | _flags.isShowingAlert = isShowing; 380 | if (isShowing) { 381 | PSTVisibleAlertsCount++; 382 | } else { 383 | PSTVisibleAlertsCount--; 384 | } 385 | } 386 | } 387 | 388 | - (void)showActionSheetWithSender:(id)sender fallbackView:(UIView *)view animated:(BOOL)animated { 389 | UIActionSheet *actionSheet = self.actionSheet; 390 | BOOL isIPad = UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad; 391 | if (isIPad && [sender isKindOfClass:UIBarButtonItem.class]) { 392 | [actionSheet showFromBarButtonItem:sender animated:animated]; 393 | } else if ([sender isKindOfClass:UIToolbar.class]) { 394 | [actionSheet showFromToolbar:sender]; 395 | } else if ([sender isKindOfClass:UITabBar.class]) { 396 | [actionSheet showFromTabBar:sender]; 397 | } else if ([view isKindOfClass:UIToolbar.class]) { 398 | [actionSheet showFromToolbar:(UIToolbar *)view]; 399 | } else if ([view isKindOfClass:UITabBar.class]) { 400 | [actionSheet showFromTabBar:(UITabBar *)view]; 401 | } else if (isIPad && [sender isKindOfClass:UIView.class]) { 402 | [actionSheet showFromRect:[sender bounds] inView:sender animated:animated]; 403 | } else if ([sender isKindOfClass:NSValue.class]) { 404 | [actionSheet showFromRect:[sender CGRectValue] inView:view animated:animated]; 405 | } else { 406 | [actionSheet showInView:view]; 407 | } 408 | } 409 | 410 | - (void)dismissAnimated:(BOOL)animated completion:(void (^)(void))completion { 411 | if ([self alertControllerAvailable]) { 412 | [self.alertController dismissViewControllerAnimated:animated completion:completion]; 413 | } else { 414 | // Make sure the completion block is called. 415 | if (completion) { 416 | [self addDidDismissBlock:^(PSTAlertAction *action) { completion(); }]; 417 | } 418 | if (self.preferredStyle == PSTAlertControllerStyleActionSheet) { 419 | [self.actionSheet dismissWithClickedButtonIndex:self.actionSheet.cancelButtonIndex animated:animated]; 420 | } else { 421 | [self.alertView dismissWithClickedButtonIndex:self.alertView.cancelButtonIndex animated:animated]; 422 | } 423 | } 424 | } 425 | 426 | - (id)presentedObject { 427 | if ([self alertControllerAvailable]) { 428 | return self.alertController; 429 | } else { 430 | if (self.preferredStyle == PSTAlertControllerStyleActionSheet) { 431 | return self.actionSheet; 432 | } else { 433 | return self.alertView; 434 | } 435 | } 436 | } 437 | 438 | /////////////////////////////////////////////////////////////////////////////////////////// 439 | #pragma mark - Will/Did Dismiss Observers 440 | 441 | - (void)addWillDismissBlock:(void (^)(PSTAlertAction *action))willDismissBlock { 442 | NSParameterAssert(willDismissBlock); 443 | self.willDismissBlocks = [[NSArray arrayWithArray:self.willDismissBlocks] arrayByAddingObject:willDismissBlock]; 444 | } 445 | 446 | - (void)addDidDismissBlock:(void (^)(PSTAlertAction *action))didDismissBlock { 447 | NSParameterAssert(didDismissBlock); 448 | self.didDismissBlocks = [[NSArray arrayWithArray:self.didDismissBlocks] arrayByAddingObject:didDismissBlock]; 449 | } 450 | 451 | /////////////////////////////////////////////////////////////////////////////////////////// 452 | #pragma mark - Memory Management 453 | 454 | - (void)moveSheetToWeakStorage { 455 | NSParameterAssert(self.strongSheetStorage); 456 | 457 | objc_setAssociatedObject(self.strongSheetStorage, _cmd, self, OBJC_ASSOCIATION_RETAIN_NONATOMIC); // bind lifetime 458 | self.weakSheetStorage = self.strongSheetStorage; 459 | self.strongSheetStorage = nil; 460 | } 461 | 462 | /////////////////////////////////////////////////////////////////////////////////////////// 463 | #pragma mark - Execute Actions 464 | 465 | - (PSTAlertAction *)actionForButtonIndex:(NSInteger)index { 466 | return index >= 0 ? self.actions[index] : nil; 467 | } 468 | 469 | - (void)performBlocks:(NSString *)blocksStorageName withAction:(PSTAlertAction *)alertAction { 470 | // Load variable and nil out. 471 | NSArray *blocks = [self valueForKey:blocksStorageName]; 472 | [self setValue:nil forKey:blocksStorageName]; 473 | 474 | for (void (^block)(PSTAlertAction *action) in blocks) { 475 | block(alertAction); 476 | } 477 | } 478 | 479 | - (void)viewWillDismissWithButtonIndex:(NSInteger)buttonIndex { 480 | PSTAlertAction *action = [self actionForButtonIndex:buttonIndex]; 481 | self.executedAlertAction = action; 482 | 483 | [self performBlocks:PROPERTY(willDismissBlocks) withAction:action]; 484 | self.willDismissBlocks = nil; 485 | 486 | [self setIsShowingAlert:NO]; 487 | } 488 | 489 | - (void)viewDidDismissWithButtonIndex:(NSInteger)buttonIndex { 490 | PSTAlertAction *action = [self actionForButtonIndex:buttonIndex]; 491 | [action performAction]; 492 | 493 | [self performBlocks:PROPERTY(didDismissBlocks) withAction:action]; 494 | } 495 | 496 | /////////////////////////////////////////////////////////////////////////////////////////// 497 | #pragma mark - UIActionSheetDelegate 498 | 499 | - (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex { 500 | [self viewWillDismissWithButtonIndex:buttonIndex]; 501 | } 502 | 503 | // Called when a button is clicked. The view will be automatically dismissed after this call returns. 504 | - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { 505 | [self viewDidDismissWithButtonIndex:buttonIndex]; 506 | } 507 | 508 | /////////////////////////////////////////////////////////////////////////////////////////// 509 | #pragma mark - UIAlertViewDelegate 510 | 511 | - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex { 512 | [self viewWillDismissWithButtonIndex:buttonIndex]; 513 | } 514 | 515 | - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { 516 | [self viewDidDismissWithButtonIndex:buttonIndex]; 517 | } 518 | 519 | @end 520 | 521 | @implementation PSTAlertController (Convenience) 522 | 523 | + (instancetype)actionWithTitle:(NSString *)title handler:(void (^)(PSTAlertAction *action))handler { 524 | return [[self alloc] initWithTitle:title style:PSTAlertActionStyleDefault handler:handler]; 525 | } 526 | 527 | + (instancetype)alertWithTitle:(NSString *)title message:(NSString *)message { 528 | return [[self alloc] initWithTitle:title message:message preferredStyle:PSTAlertControllerStyleAlert]; 529 | } 530 | 531 | + (instancetype)actionSheetWithTitle:(NSString *)title { 532 | return [[self alloc] initWithTitle:title message:nil preferredStyle:PSTAlertControllerStyleActionSheet]; 533 | } 534 | 535 | + (instancetype)presentDismissableAlertWithTitle:(NSString *)title message:(NSString *)message controller:(UIViewController *)controller { 536 | PSTAlertController *alertController = [self alertWithTitle:title message:message]; 537 | [alertController addAction:[PSTAlertAction actionWithTitle:NSLocalizedString(@"Dismiss", @"") style:PSTAlertActionStyleCancel handler:NULL]]; 538 | [alertController showWithSender:nil controller:controller animated:YES completion:NULL]; 539 | return alertController; 540 | } 541 | 542 | + (instancetype)presentDismissableAlertWithTitle:(NSString *)title error:(NSError *)error controller:(UIViewController *)controller { 543 | NSString *message = error.localizedDescription; 544 | if (error.localizedFailureReason.length > 0) { 545 | message = [NSString stringWithFormat:@"%@ (%@)", error.localizedDescription, error.localizedFailureReason]; 546 | } 547 | 548 | return [self presentDismissableAlertWithTitle:title message:message controller:controller]; 549 | } 550 | 551 | - (void)addCancelActionWithHandler:(void (^)(PSTAlertAction *action))handler { 552 | [self addAction:[PSTAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"") style:PSTAlertActionStyleCancel handler:handler]]; 553 | } 554 | 555 | @end 556 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PSTAlertController 2 | ================== 3 | 4 | API similar to `UIAlertController`, backwards compatible to iOS 7. Will use the new shiny API when you run iOS 8. 5 | 6 | We cheat a bit by having `PSTAlertController` superclass be `NSObject`, but for most use cases it's still a lot more convenient than using `UIAlertView`/`UIActionSheet`. 7 | 8 | Functions that are only possible since `UIAlertController` are not back-ported. This is a simple wrapper to make your life more convenient, not a complete rewrite. 9 | 10 | Written for [PSPDFKit, The leading framework for displaying and annotating PDFs in your iOS apps.](https://pspdfkit.com/). 11 | It's a commercial library, but sometimes I just love to share. 12 | 13 | ## Compatbility 14 | 15 | Tested with iOS 7-9, Xcode 7 and ARC. 16 | 17 | ## License 18 | 19 | MIT, see LICENSE file. 20 | --------------------------------------------------------------------------------