mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
36 lines
1.2 KiB
Swift
36 lines
1.2 KiB
Swift
//
|
|
// NotificationService.swift
|
|
// NotificationServiceExtension
|
|
//
|
|
// Created by huangfeng on 2018/12/17.
|
|
// Copyright © 2018 Fin. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import UserNotifications
|
|
import RealmSwift
|
|
class NotificationService: UNNotificationServiceExtension {
|
|
|
|
var contentHandler: ((UNNotificationContent) -> Void)?
|
|
var bestAttemptContent: UNMutableNotificationContent?
|
|
|
|
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
|
|
self.contentHandler = contentHandler
|
|
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
|
|
|
|
if let bestAttemptContent = bestAttemptContent {
|
|
let userInfo = bestAttemptContent.userInfo
|
|
if userInfo["automaticallycopy"] as? String == "1"{
|
|
if let copy = userInfo["copy"] as? String {
|
|
UIPasteboard.general.string = copy
|
|
}
|
|
else{
|
|
UIPasteboard.general.string = bestAttemptContent.body
|
|
}
|
|
}
|
|
contentHandler(bestAttemptContent)
|
|
}
|
|
}
|
|
|
|
}
|