import UIKit import Intents
class ViewController: UIViewController {
override func viewDidLoad() { super.viewDidLoad() }
@IBAction func sendNotification(_ sender: Any) { var content = UNMutableNotificationContent()
content.title = "Test" content.subtitle = "Solo" content.body = "Test" content.sound = UNNotificationSound.default content.categoryIdentifier = "categoryName"
var personNameComponents = PersonNameComponents() personNameComponents.nickname = "Sender Name"
let avatar = INImage(imageData: UIImage(named: "Solo")?.pngData() ?? Data())
let senderPerson = INPerson( personHandle: INPersonHandle(value: "1233211234", type: .unknown), nameComponents: personNameComponents, displayName: "Sender Name", image: avatar, contactIdentifier: nil, customIdentifier: nil, isMe: false, suggestionType: .none )
let intent = INSendMessageIntent( recipients: .none, outgoingMessageType: .outgoingMessageText, content: "Test", speakableGroupName: INSpeakableString(spokenPhrase: "Sender Name"), conversationIdentifier: "sampleConversationIdentifier", serviceName: nil, sender: senderPerson, attachments: nil )
intent.setImage(avatar, forParameterNamed: .sender)
let interaction = INInteraction(intent: intent, response: nil) interaction.direction = .incoming
interaction.donate(completion: nil)
do { content = try content.updating(from: intent) as! UNMutableNotificationContent } catch { print(error) }
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 3, repeats: false)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) }
}