Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

iOS 10~ Experiments - New API Components - New User Notifications with 3DTouch and iPhone 7.

NotificationsYou must be signed in to change notification settings

Sweefties/iOS10-NewAPI-UserNotifications-Example

Repository files navigation

iOS 10 - New API - User Notifications - 3DTouch Example

iOS 10~ Experiments - New API Components - New User Notifications with 3DTouch and iPhone 7.

Example

Requirements

  • = XCode 8.0

  • = Swift 3.

  • = iOS 10.0.

  • = 3D Touch Devices or iOS 10 supported.

Tested on iPhone SE, iPhone 6, iPhone 7 iOS 10.0 Simulators and physicals iPhone 7, iPhone 6, iPhone SE.

Important

This is a Xcode 8+ / Swift 3+ project.To run on physicals devices, change the team provisioning profile.

References

Read :UNUserNotificationCenter

API Reference :UserNotifications

Usage

To run the example project, download or clone the repo.

Example Code!

Import Framework :

import UserNotifications

RegisterUNUserNotificationCenter

func application(_ application:UIApplication, didFinishLaunchingWithOptions launchOptions:[UIApplicationLaunchOptionsKey:Any]?)->Bool{letcenter=UNUserNotificationCenter.current()  // define actionsletac1=setAction(id:UNIdentifiers.reply, title:"Reply")letac2=setAction(id:UNIdentifiers.share, title:"Share")letac3=setAction(id:UNIdentifiers.follow, title:"Follow")letac4=setAction(id:UNIdentifiers.destructive, title:"Cancel", options:.destructive)letac5=setAction(id:UNIdentifiers.direction, title:"Get Direction")  // define categoriesletcat1=setCategory(identifier:UNIdentifiers.category, action:[ac1, ac2, ac3, ac4], intentIdentifiers:[])letcat2=setCategory(identifier:UNIdentifiers.customContent, action:[ac5, ac4], intentIdentifiers:[])letcat3=setCategory(identifier:UNIdentifiers.image, action:[ac2], intentIdentifiers:[], options:.allowInCarPlay)  // Registers your app’s notification types and the custom actions that they support.  center.setNotificationCategories([cat1, cat2, cat3])  // Requests authorization to interact with the user when local and remote notifications arrive.  center.requestAuthorization(options:[.badge,.alert,.sound]){(success, error)inprint(error?.localizedDescription)}returntrue}

Set Actions and Categories :

/// Set User Notifications Action.////// - Parameter id:             `String` identifier string value/// - Parameter title:          `String` title string value/// - Parameter options:        `UNNotificationActionOptions` bevavior to the action as `OptionSet`////// - Returns:                  `UNNotificationAction`///privatefunc setAction(id:String, title:String, options:UNNotificationActionOptions=[])->UNNotificationAction{letaction=UNNotificationAction(identifier: id, title: title, options: options)return action}/// Set User Notifications Category.////// - Parameter identifier:         `String`/// - Parameter action:             `[UNNotificationAction]` ask to perform in response to///                                 a delivered notification/// - Parameter intentIdentifiers:  `[String]` array of `String`/// - Parameter options:            `[UNNotificationCategoryOptions]` handle notifications,///                                 associated with this category `OptionSet`////// - Returns:                      `UNNotificationCategory`///privatefunc setCategory(identifier:String, action:[UNNotificationAction],  intentIdentifiers:[String], options:UNNotificationCategoryOptions=[])->UNNotificationCategory{letcategory=UNNotificationCategory(identifier: identifier, actions: action, intentIdentifiers: intentIdentifiers, options: options)return category}

Add request to currentUNUserNotificationCenter

letrequest=UNNotificationRequest(identifier:UNIdentifiers.request, content:content[type.rawValue], trigger:nil)UNUserNotificationCenter.current().add(request){ errorinUNUserNotificationCenter.current().delegate=selfif(error!=nil){      //handle here}}

Et Voilà!

  • Build and Run!
  • By pressing lightly (Peek) and pressing a little more firmly to actually open content (Pop)
  • Optimized for Devices : iPhone 6s and others 3D Touch devices!

About

iOS 10~ Experiments - New API Components - New User Notifications with 3DTouch and iPhone 7.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp