├── NotificationDemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ ├── PeterPan.xcuserdatad │ └── xcschemes │ │ ├── NotificationDemo.xcscheme │ │ └── xcschememanagement.plist │ └── simon.xcuserdatad │ └── xcschemes │ ├── NotificationDemo.xcscheme │ └── xcschememanagement.plist ├── NotificationDemo ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ ├── 12342332_822629614525610_1289817131792236907_n.png │ │ └── Contents.json │ ├── Contents.json │ └── flower.imageset │ │ ├── 12342332_822629614525610_1289817131792236907_n.jpg │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── ViewController.swift └── pic.jpg ├── NotificationDemoStarter.zip ├── README.md └── user-notification-featured.jpg /NotificationDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A611E2671D61C62400B1D526 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A611E2661D61C62400B1D526 /* AppDelegate.swift */; }; 11 | A611E2691D61C62400B1D526 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A611E2681D61C62400B1D526 /* ViewController.swift */; }; 12 | A611E26C1D61C62400B1D526 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A611E26A1D61C62400B1D526 /* Main.storyboard */; }; 13 | A611E26E1D61C62400B1D526 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A611E26D1D61C62400B1D526 /* Assets.xcassets */; }; 14 | A611E2711D61C62400B1D526 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A611E26F1D61C62400B1D526 /* LaunchScreen.storyboard */; }; 15 | A67E03FD1D6314DB00B5DE9D /* pic.jpg in Resources */ = {isa = PBXBuildFile; fileRef = A67E03FC1D6314DB00B5DE9D /* pic.jpg */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | A611E2631D61C62400B1D526 /* NotificationDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NotificationDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | A611E2661D61C62400B1D526 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | A611E2681D61C62400B1D526 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | A611E26B1D61C62400B1D526 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | A611E26D1D61C62400B1D526 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | A611E2701D61C62400B1D526 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | A611E2721D61C62400B1D526 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | A67E03FC1D6314DB00B5DE9D /* pic.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = pic.jpg; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | A611E2601D61C62400B1D526 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | A611E25A1D61C62400B1D526 = { 41 | isa = PBXGroup; 42 | children = ( 43 | A611E2651D61C62400B1D526 /* NotificationDemo */, 44 | A611E2641D61C62400B1D526 /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | A611E2641D61C62400B1D526 /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | A611E2631D61C62400B1D526 /* NotificationDemo.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | A611E2651D61C62400B1D526 /* NotificationDemo */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | A67E03FC1D6314DB00B5DE9D /* pic.jpg */, 60 | A611E2661D61C62400B1D526 /* AppDelegate.swift */, 61 | A611E2681D61C62400B1D526 /* ViewController.swift */, 62 | A611E26A1D61C62400B1D526 /* Main.storyboard */, 63 | A611E26D1D61C62400B1D526 /* Assets.xcassets */, 64 | A611E26F1D61C62400B1D526 /* LaunchScreen.storyboard */, 65 | A611E2721D61C62400B1D526 /* Info.plist */, 66 | ); 67 | path = NotificationDemo; 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | A611E2621D61C62400B1D526 /* NotificationDemo */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = A611E2751D61C62400B1D526 /* Build configuration list for PBXNativeTarget "NotificationDemo" */; 76 | buildPhases = ( 77 | A611E25F1D61C62400B1D526 /* Sources */, 78 | A611E2601D61C62400B1D526 /* Frameworks */, 79 | A611E2611D61C62400B1D526 /* Resources */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = NotificationDemo; 86 | productName = NotificationDemo; 87 | productReference = A611E2631D61C62400B1D526 /* NotificationDemo.app */; 88 | productType = "com.apple.product-type.application"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | A611E25B1D61C62400B1D526 /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastSwiftUpdateCheck = 0800; 97 | LastUpgradeCheck = 0800; 98 | ORGANIZATIONNAME = "Peter Pan"; 99 | TargetAttributes = { 100 | A611E2621D61C62400B1D526 = { 101 | CreatedOnToolsVersion = 8.0; 102 | ProvisioningStyle = Automatic; 103 | }; 104 | }; 105 | }; 106 | buildConfigurationList = A611E25E1D61C62400B1D526 /* Build configuration list for PBXProject "NotificationDemo" */; 107 | compatibilityVersion = "Xcode 3.2"; 108 | developmentRegion = English; 109 | hasScannedForEncodings = 0; 110 | knownRegions = ( 111 | en, 112 | Base, 113 | ); 114 | mainGroup = A611E25A1D61C62400B1D526; 115 | productRefGroup = A611E2641D61C62400B1D526 /* Products */; 116 | projectDirPath = ""; 117 | projectRoot = ""; 118 | targets = ( 119 | A611E2621D61C62400B1D526 /* NotificationDemo */, 120 | ); 121 | }; 122 | /* End PBXProject section */ 123 | 124 | /* Begin PBXResourcesBuildPhase section */ 125 | A611E2611D61C62400B1D526 /* Resources */ = { 126 | isa = PBXResourcesBuildPhase; 127 | buildActionMask = 2147483647; 128 | files = ( 129 | A67E03FD1D6314DB00B5DE9D /* pic.jpg in Resources */, 130 | A611E2711D61C62400B1D526 /* LaunchScreen.storyboard in Resources */, 131 | A611E26E1D61C62400B1D526 /* Assets.xcassets in Resources */, 132 | A611E26C1D61C62400B1D526 /* Main.storyboard in Resources */, 133 | ); 134 | runOnlyForDeploymentPostprocessing = 0; 135 | }; 136 | /* End PBXResourcesBuildPhase section */ 137 | 138 | /* Begin PBXSourcesBuildPhase section */ 139 | A611E25F1D61C62400B1D526 /* Sources */ = { 140 | isa = PBXSourcesBuildPhase; 141 | buildActionMask = 2147483647; 142 | files = ( 143 | A611E2691D61C62400B1D526 /* ViewController.swift in Sources */, 144 | A611E2671D61C62400B1D526 /* AppDelegate.swift in Sources */, 145 | ); 146 | runOnlyForDeploymentPostprocessing = 0; 147 | }; 148 | /* End PBXSourcesBuildPhase section */ 149 | 150 | /* Begin PBXVariantGroup section */ 151 | A611E26A1D61C62400B1D526 /* Main.storyboard */ = { 152 | isa = PBXVariantGroup; 153 | children = ( 154 | A611E26B1D61C62400B1D526 /* Base */, 155 | ); 156 | name = Main.storyboard; 157 | sourceTree = ""; 158 | }; 159 | A611E26F1D61C62400B1D526 /* LaunchScreen.storyboard */ = { 160 | isa = PBXVariantGroup; 161 | children = ( 162 | A611E2701D61C62400B1D526 /* Base */, 163 | ); 164 | name = LaunchScreen.storyboard; 165 | sourceTree = ""; 166 | }; 167 | /* End PBXVariantGroup section */ 168 | 169 | /* Begin XCBuildConfiguration section */ 170 | A611E2731D61C62400B1D526 /* Debug */ = { 171 | isa = XCBuildConfiguration; 172 | buildSettings = { 173 | ALWAYS_SEARCH_USER_PATHS = NO; 174 | CLANG_ANALYZER_NONNULL = YES; 175 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 176 | CLANG_CXX_LIBRARY = "libc++"; 177 | CLANG_ENABLE_MODULES = YES; 178 | CLANG_ENABLE_OBJC_ARC = YES; 179 | CLANG_WARN_BOOL_CONVERSION = YES; 180 | CLANG_WARN_CONSTANT_CONVERSION = YES; 181 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 182 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 183 | CLANG_WARN_EMPTY_BODY = YES; 184 | CLANG_WARN_ENUM_CONVERSION = YES; 185 | CLANG_WARN_INFINITE_RECURSION = YES; 186 | CLANG_WARN_INT_CONVERSION = YES; 187 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 188 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 189 | CLANG_WARN_UNREACHABLE_CODE = YES; 190 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 191 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 192 | COPY_PHASE_STRIP = NO; 193 | DEBUG_INFORMATION_FORMAT = dwarf; 194 | ENABLE_STRICT_OBJC_MSGSEND = YES; 195 | ENABLE_TESTABILITY = YES; 196 | GCC_C_LANGUAGE_STANDARD = gnu99; 197 | GCC_DYNAMIC_NO_PIC = NO; 198 | GCC_NO_COMMON_BLOCKS = YES; 199 | GCC_OPTIMIZATION_LEVEL = 0; 200 | GCC_PREPROCESSOR_DEFINITIONS = ( 201 | "DEBUG=1", 202 | "$(inherited)", 203 | ); 204 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 205 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 206 | GCC_WARN_UNDECLARED_SELECTOR = YES; 207 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 208 | GCC_WARN_UNUSED_FUNCTION = YES; 209 | GCC_WARN_UNUSED_VARIABLE = YES; 210 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 211 | MTL_ENABLE_DEBUG_INFO = YES; 212 | ONLY_ACTIVE_ARCH = YES; 213 | SDKROOT = iphoneos; 214 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 215 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 216 | }; 217 | name = Debug; 218 | }; 219 | A611E2741D61C62400B1D526 /* Release */ = { 220 | isa = XCBuildConfiguration; 221 | buildSettings = { 222 | ALWAYS_SEARCH_USER_PATHS = NO; 223 | CLANG_ANALYZER_NONNULL = YES; 224 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 225 | CLANG_CXX_LIBRARY = "libc++"; 226 | CLANG_ENABLE_MODULES = YES; 227 | CLANG_ENABLE_OBJC_ARC = YES; 228 | CLANG_WARN_BOOL_CONVERSION = YES; 229 | CLANG_WARN_CONSTANT_CONVERSION = YES; 230 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 231 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 232 | CLANG_WARN_EMPTY_BODY = YES; 233 | CLANG_WARN_ENUM_CONVERSION = YES; 234 | CLANG_WARN_INFINITE_RECURSION = YES; 235 | CLANG_WARN_INT_CONVERSION = YES; 236 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 237 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 238 | CLANG_WARN_UNREACHABLE_CODE = YES; 239 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 240 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 241 | COPY_PHASE_STRIP = NO; 242 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 243 | ENABLE_NS_ASSERTIONS = NO; 244 | ENABLE_STRICT_OBJC_MSGSEND = YES; 245 | GCC_C_LANGUAGE_STANDARD = gnu99; 246 | GCC_NO_COMMON_BLOCKS = YES; 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 = 10.0; 254 | MTL_ENABLE_DEBUG_INFO = NO; 255 | SDKROOT = iphoneos; 256 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 257 | VALIDATE_PRODUCT = YES; 258 | }; 259 | name = Release; 260 | }; 261 | A611E2761D61C62400B1D526 /* Debug */ = { 262 | isa = XCBuildConfiguration; 263 | buildSettings = { 264 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 265 | DEVELOPMENT_TEAM = ""; 266 | INFOPLIST_FILE = NotificationDemo/Info.plist; 267 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 268 | PRODUCT_BUNDLE_IDENTIFIER = com.appcoda.UserNotificationDemo; 269 | PRODUCT_NAME = "$(TARGET_NAME)"; 270 | SWIFT_VERSION = 3.0; 271 | }; 272 | name = Debug; 273 | }; 274 | A611E2771D61C62400B1D526 /* Release */ = { 275 | isa = XCBuildConfiguration; 276 | buildSettings = { 277 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 278 | DEVELOPMENT_TEAM = ""; 279 | INFOPLIST_FILE = NotificationDemo/Info.plist; 280 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 281 | PRODUCT_BUNDLE_IDENTIFIER = com.appcoda.UserNotificationDemo; 282 | PRODUCT_NAME = "$(TARGET_NAME)"; 283 | SWIFT_VERSION = 3.0; 284 | }; 285 | name = Release; 286 | }; 287 | /* End XCBuildConfiguration section */ 288 | 289 | /* Begin XCConfigurationList section */ 290 | A611E25E1D61C62400B1D526 /* Build configuration list for PBXProject "NotificationDemo" */ = { 291 | isa = XCConfigurationList; 292 | buildConfigurations = ( 293 | A611E2731D61C62400B1D526 /* Debug */, 294 | A611E2741D61C62400B1D526 /* Release */, 295 | ); 296 | defaultConfigurationIsVisible = 0; 297 | defaultConfigurationName = Release; 298 | }; 299 | A611E2751D61C62400B1D526 /* Build configuration list for PBXNativeTarget "NotificationDemo" */ = { 300 | isa = XCConfigurationList; 301 | buildConfigurations = ( 302 | A611E2761D61C62400B1D526 /* Debug */, 303 | A611E2771D61C62400B1D526 /* Release */, 304 | ); 305 | defaultConfigurationIsVisible = 0; 306 | defaultConfigurationName = Release; 307 | }; 308 | /* End XCConfigurationList section */ 309 | }; 310 | rootObject = A611E25B1D61C62400B1D526 /* Project object */; 311 | } 312 | -------------------------------------------------------------------------------- /NotificationDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /NotificationDemo.xcodeproj/xcuserdata/PeterPan.xcuserdatad/xcschemes/NotificationDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /NotificationDemo.xcodeproj/xcuserdata/PeterPan.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | NotificationDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | A611E2621D61C62400B1D526 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /NotificationDemo.xcodeproj/xcuserdata/simon.xcuserdatad/xcschemes/NotificationDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /NotificationDemo.xcodeproj/xcuserdata/simon.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | NotificationDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | A611E2621D61C62400B1D526 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /NotificationDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // NotificationDemo 4 | // 5 | // Created by Peter Pan on 8/15/16. 6 | // Copyright © 2016 Peter Pan. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import UserNotifications 11 | 12 | @UIApplicationMain 13 | class AppDelegate: UIResponder, UIApplicationDelegate { 14 | 15 | var window: UIWindow? 16 | 17 | 18 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 19 | 20 | // Override point for customization after application launch. 21 | UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: { granted, error in 22 | if granted { 23 | print("使用者同意了,每天都能收到來自米花兒的幸福訊息") 24 | } 25 | else { 26 | print("使用者不同意,不喜歡米花兒,哭哭!") 27 | } 28 | 29 | }) 30 | 31 | UNUserNotificationCenter.current().delegate = self 32 | 33 | let likeAction = UNNotificationAction(identifier: "like", title: "好感動", options: [.foreground]) 34 | let dislikeAction = UNNotificationAction(identifier: "dislike", title: "沒感覺", options: []) 35 | let category = UNNotificationCategory(identifier: "luckyMessage", actions: [likeAction, dislikeAction], intentIdentifiers: [], options: []) 36 | UNUserNotificationCenter.current().setNotificationCategories([category]) 37 | 38 | return true 39 | } 40 | 41 | func applicationWillResignActive(_ application: UIApplication) { 42 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 43 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 44 | } 45 | 46 | func applicationDidEnterBackground(_ application: UIApplication) { 47 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 48 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 49 | } 50 | 51 | func applicationWillEnterForeground(_ application: UIApplication) { 52 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 53 | } 54 | 55 | func applicationDidBecomeActive(_ application: UIApplication) { 56 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 57 | } 58 | 59 | func applicationWillTerminate(_ application: UIApplication) { 60 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 61 | } 62 | } 63 | 64 | extension AppDelegate: UNUserNotificationCenterDelegate { 65 | 66 | func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { 67 | completionHandler([.badge, .sound, .alert]) 68 | } 69 | 70 | func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { 71 | 72 | let content = response.notification.request.content 73 | print("title \(content.title)") 74 | print("userInfo \(content.userInfo)") 75 | print("actionIdentifier \(response.actionIdentifier)") 76 | 77 | completionHandler() 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /NotificationDemo/Assets.xcassets/AppIcon.appiconset/12342332_822629614525610_1289817131792236907_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/UserNotificationDemo/5b9270ced9f3761b77d30c46079518304fcccca6/NotificationDemo/Assets.xcassets/AppIcon.appiconset/12342332_822629614525610_1289817131792236907_n.png -------------------------------------------------------------------------------- /NotificationDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "60x60", 35 | "idiom" : "iphone", 36 | "filename" : "12342332_822629614525610_1289817131792236907_n.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "idiom" : "iphone", 41 | "size" : "60x60", 42 | "scale" : "3x" 43 | } 44 | ], 45 | "info" : { 46 | "version" : 1, 47 | "author" : "xcode" 48 | } 49 | } -------------------------------------------------------------------------------- /NotificationDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /NotificationDemo/Assets.xcassets/flower.imageset/12342332_822629614525610_1289817131792236907_n.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/UserNotificationDemo/5b9270ced9f3761b77d30c46079518304fcccca6/NotificationDemo/Assets.xcassets/flower.imageset/12342332_822629614525610_1289817131792236907_n.jpg -------------------------------------------------------------------------------- /NotificationDemo/Assets.xcassets/flower.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "12342332_822629614525610_1289817131792236907_n.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /NotificationDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /NotificationDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /NotificationDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | 米花兒 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 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 | 40 | 41 | -------------------------------------------------------------------------------- /NotificationDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // NotificationDemo 4 | // 5 | // Created by Peter Pan on 8/15/16. 6 | // Copyright © 2016 Peter Pan. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import UserNotifications 11 | 12 | class ViewController: UIViewController, UIPickerViewDelegate { 13 | 14 | @IBAction func createNotification(_ sender: AnyObject) { 15 | 16 | let content = UNMutableNotificationContent() 17 | content.title = "體驗過了,才是你的。" 18 | content.subtitle = "米花兒" 19 | content.body = "不要追問為什麼,就笨拙地走入未知。感受眼前的怦然與顫抖,聽聽左邊的碎裂和跳動。不管好的壞的,只有體驗過了,才是你的。" 20 | content.badge = 1 21 | content.sound = UNNotificationSound.default() 22 | content.categoryIdentifier = "luckyMessage" 23 | 24 | let imageURL = Bundle.main.url(forResource: "pic", withExtension: "jpg") 25 | let attachment = try! UNNotificationAttachment(identifier: "", url: imageURL!, options: nil) 26 | content.attachments = [attachment] 27 | content.userInfo = ["link":"https://www.facebook.com/himinihana/photos/a.104501733005072.5463.100117360110176/981809495274287"] 28 | 29 | let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false) 30 | let request = UNNotificationRequest(identifier: "notification1", content: content, trigger: trigger) 31 | UNUserNotificationCenter.current().add(request, withCompletionHandler: nil) 32 | 33 | } 34 | 35 | override func viewDidLoad() { 36 | super.viewDidLoad() 37 | // Do any additional setup after loading the view, typically from a nib. 38 | } 39 | 40 | override func didReceiveMemoryWarning() { 41 | super.didReceiveMemoryWarning() 42 | // Dispose of any resources that can be recreated. 43 | } 44 | 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /NotificationDemo/pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/UserNotificationDemo/5b9270ced9f3761b77d30c46079518304fcccca6/NotificationDemo/pic.jpg -------------------------------------------------------------------------------- /NotificationDemoStarter.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/UserNotificationDemo/5b9270ced9f3761b77d30c46079518304fcccca6/NotificationDemoStarter.zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A simple demo of UserNotifications Framework in iOS 10 2 | 3 | ![](user-notification-featured.jpg) 4 | 5 | In iOS 10, Apple introduces a new framework called UserNotifications. If you want to learn about how this demo was built, you can refer to the tutorial below, written by Peter (in Chinese): 6 | 7 | 結合 iOS 10 的 User Notifications:傳送米花兒的幸福打氣通知 8 | 9 | http://www.appcoda.com.tw/ios10-user-notifications/ 10 | -------------------------------------------------------------------------------- /user-notification-featured.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/UserNotificationDemo/5b9270ced9f3761b77d30c46079518304fcccca6/user-notification-featured.jpg --------------------------------------------------------------------------------