All Projects → Sweefties → iOS10-NewAPI-UserNotifications-Example

Sweefties / iOS10-NewAPI-UserNotifications-Example

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

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to iOS10-NewAPI-UserNotifications-Example

ImageCropper
✂️ Detect and crop faces, barcodes, texts or rectangle in image with iOS 11 Vision (iOS 10 Core Image) api.(图片裁剪:支持人脸、二维码/条形码、文本、方框)
Stars: ✭ 17 (-5.56%)
Mutual labels:  ios10
nativescript-app-shortcuts
👇 Home Icon Actions for your NativeScript app, now also for Android!
Stars: ✭ 45 (+150%)
Mutual labels:  3d-touch
Beginning-iOS-Programming-with-Swift
《Beginning iOS 10 Programming with Swift》代码
Stars: ✭ 30 (+66.67%)
Mutual labels:  ios10
iOS-Restrictions-Recovery
Can find the Restrictions or Screen Time passcode of any iOS 7.0-12.5.5 device. iOS 13 and 14 should work in theory, but Keychain-Dumper is very hit or miss on those versions
Stars: ✭ 50 (+177.78%)
Mutual labels:  ios10
ScoutAR
Augmented reality app displays nearby restaurant information in a live camera and map view.
Stars: ✭ 28 (+55.56%)
Mutual labels:  ios10
iOS-10-Sampler
Code examples for the new features of iOS 10.
Stars: ✭ 72 (+300%)
Mutual labels:  ios10
VKLocalNotifications
This project covers all the requried code to trigger UILocalNotifications. It can be helpful when you want to trigger a Push Notification when a user reaches a particular location. Does not need internet connection.
Stars: ✭ 52 (+188.89%)
Mutual labels:  unusernotificationcenter
RichNotifications
No description or website provided.
Stars: ✭ 44 (+144.44%)
Mutual labels:  ios10
laravel-user-notifications
User notifications for Laravel 5+
Stars: ✭ 24 (+33.33%)
Mutual labels:  user-notifications
react-pressure
React HOC that enables 3D Touch on other components, available via npm
Stars: ✭ 13 (-27.78%)
Mutual labels:  3d-touch
Cordova Plugin Local Notifications
Cordova Local-Notification Plugin
Stars: ✭ 2,525 (+13927.78%)
Mutual labels:  user-notifications
Hxphotopicker
图片/视频选择器 - 支持LivePhoto、GIF图片选择、3DTouch预览、在线下载iCloud上的资源、编辑图片/视频、浏览网络图片 功能 Imitation wx photo/image picker - support for LivePhoto, GIF image selection, 3DTouch preview, Download the resources on iCloud online, browse the web image function
Stars: ✭ 2,363 (+13027.78%)
Mutual labels:  3d-touch
Pressure
👇💥 JavaScript library for handling Force Touch, 3D Touch, and Pointer Pressure.
Stars: ✭ 2,785 (+15372.22%)
Mutual labels:  3d-touch
Ios 10 Sampler
Code examples for new APIs of iOS 10.
Stars: ✭ 3,341 (+18461.11%)
Mutual labels:  ios10
Disk
Delightful framework for iOS to easily persist structs, images, and data
Stars: ✭ 2,896 (+15988.89%)
Mutual labels:  ios10

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

Register UNUserNotificationCenter

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

  let center = UNUserNotificationCenter.current()

  // define actions
  let ac1 = setAction(id: UNIdentifiers.reply, title: "Reply")
  let ac2 = setAction(id: UNIdentifiers.share, title: "Share")
  let ac3 = setAction(id: UNIdentifiers.follow, title: "Follow")
  let ac4 = setAction(id: UNIdentifiers.destructive, title: "Cancel", options: .destructive)
  let ac5 = setAction(id: UNIdentifiers.direction, title: "Get Direction")

  // define categories
  let cat1 = setCategory(identifier: UNIdentifiers.category, action: [ac1, ac2, ac3, ac4], intentIdentifiers: [])
  let cat2 = setCategory(identifier: UNIdentifiers.customContent, action: [ac5, ac4], intentIdentifiers: [])
  let cat3 = 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) in
    print(error?.localizedDescription)
  }

  return true
}

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`
///
private func setAction(id: String, title: String, options: UNNotificationActionOptions = []) -> UNNotificationAction {

  let action = 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`
///
private func setCategory(identifier: String, action:[UNNotificationAction],  intentIdentifiers: [String], options: UNNotificationCategoryOptions = []) -> UNNotificationCategory {

  let category = UNNotificationCategory(identifier: identifier, actions: action, intentIdentifiers: intentIdentifiers, options: options)

  return category
}

Add request to current UNUserNotificationCenter

  let request = UNNotificationRequest(identifier: UNIdentifiers.request, content: content[type.rawValue], trigger: nil)
  UNUserNotificationCenter.current().add(request) { error in
    UNUserNotificationCenter.current().delegate = self
    if (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!
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].