Clean up
This commit is contained in:
@@ -5,8 +5,8 @@
|
|||||||
// Created by Joshua Higgins on 6/2/25.
|
// Created by Joshua Higgins on 6/2/25.
|
||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
|
||||||
import Messages
|
import Messages
|
||||||
|
import UIKit
|
||||||
|
|
||||||
class MessagesViewController: MSMessagesAppViewController {
|
class MessagesViewController: MSMessagesAppViewController {
|
||||||
|
|
||||||
@@ -34,10 +34,12 @@ class MessagesViewController: MSMessagesAppViewController {
|
|||||||
|
|
||||||
private func sendGIF(_ gif: GIF) {
|
private func sendGIF(_ gif: GIF) {
|
||||||
guard let conversation = activeConversation,
|
guard let conversation = activeConversation,
|
||||||
let gifURL = gif.url else { return }
|
let gifURL = gif.url
|
||||||
|
else { return }
|
||||||
|
|
||||||
// Show a loading indicator
|
// Show a loading indicator
|
||||||
let loadingAlert = UIAlertController(title: "Preparing GIF", message: "Please wait...", preferredStyle: .alert)
|
let loadingAlert = UIAlertController(
|
||||||
|
title: "Preparing GIF", message: "Please wait...", preferredStyle: .alert)
|
||||||
present(loadingAlert, animated: true)
|
present(loadingAlert, animated: true)
|
||||||
|
|
||||||
// Download the GIF data
|
// Download the GIF data
|
||||||
@@ -57,14 +59,16 @@ class MessagesViewController: MSMessagesAppViewController {
|
|||||||
|
|
||||||
// Create a temporary file URL for the GIF
|
// Create a temporary file URL for the GIF
|
||||||
let tempDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
let tempDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
||||||
let tempFileURL = tempDirectoryURL.appendingPathComponent(UUID().uuidString).appendingPathExtension("gif")
|
let tempFileURL = tempDirectoryURL.appendingPathComponent(UUID().uuidString)
|
||||||
|
.appendingPathExtension("gif")
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// Write GIF data to temporary file
|
// Write GIF data to temporary file
|
||||||
try gifData.write(to: tempFileURL)
|
try gifData.write(to: tempFileURL)
|
||||||
|
|
||||||
// Insert the GIF directly as a standard attachment into the message field
|
// Insert the GIF directly as a standard attachment into the message field
|
||||||
conversation.insertAttachment(tempFileURL, withAlternateFilename: "animated.gif") { error in
|
conversation.insertAttachment(tempFileURL, withAlternateFilename: "animated.gif") {
|
||||||
|
error in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
self.showErrorAlert(error: error)
|
self.showErrorAlert(error: error)
|
||||||
} else {
|
} else {
|
||||||
@@ -82,7 +86,8 @@ class MessagesViewController: MSMessagesAppViewController {
|
|||||||
|
|
||||||
private func showErrorAlert(error: Error? = nil, message: String? = nil) {
|
private func showErrorAlert(error: Error? = nil, message: String? = nil) {
|
||||||
let errorMessage = message ?? error?.localizedDescription ?? "An unknown error occurred"
|
let errorMessage = message ?? error?.localizedDescription ?? "An unknown error occurred"
|
||||||
let alertController = UIAlertController(title: "Error", message: errorMessage, preferredStyle: .alert)
|
let alertController = UIAlertController(
|
||||||
|
title: "Error", message: errorMessage, preferredStyle: .alert)
|
||||||
alertController.addAction(UIAlertAction(title: "OK", style: .default))
|
alertController.addAction(UIAlertAction(title: "OK", style: .default))
|
||||||
present(alertController, animated: true)
|
present(alertController, animated: true)
|
||||||
}
|
}
|
||||||
@@ -95,49 +100,12 @@ class MessagesViewController: MSMessagesAppViewController {
|
|||||||
|
|
||||||
// Refresh GIFs list when becoming active
|
// Refresh GIFs list when becoming active
|
||||||
gifCollectionVC?.viewWillAppear(true)
|
gifCollectionVC?.viewWillAppear(true)
|
||||||
|
|
||||||
// We don't need to check for custom message URLs anymore since
|
|
||||||
// we're sending standard GIF attachments
|
|
||||||
}
|
|
||||||
|
|
||||||
override func didResignActive(with conversation: MSConversation) {
|
|
||||||
// Called when the extension is about to move from the active to inactive state.
|
|
||||||
// This will happen when the user dismisses the extension, changes to a different
|
|
||||||
// conversation or quits Messages.
|
|
||||||
|
|
||||||
// Use this method to release shared resources, save user data, invalidate timers,
|
|
||||||
// and store enough state information to restore your extension to its current state
|
|
||||||
// in case it is terminated later.
|
|
||||||
}
|
|
||||||
|
|
||||||
override func didReceive(_ message: MSMessage, conversation: MSConversation) {
|
|
||||||
// Called when a message arrives that was generated by another instance of this
|
|
||||||
// extension on a remote device.
|
|
||||||
|
|
||||||
// Since we're now sending GIFs as standard attachments rather than
|
|
||||||
// custom messages, we don't need special handling for received messages
|
|
||||||
}
|
|
||||||
|
|
||||||
override func didStartSending(_ message: MSMessage, conversation: MSConversation) {
|
|
||||||
// Called when the user taps the send button.
|
|
||||||
}
|
|
||||||
|
|
||||||
override func didCancelSending(_ message: MSMessage, conversation: MSConversation) {
|
|
||||||
// Called when the user deletes the message without sending it.
|
|
||||||
|
|
||||||
// Use this to clean up state related to the deleted message.
|
|
||||||
}
|
|
||||||
|
|
||||||
override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
|
|
||||||
// Called before the extension transitions to a new presentation style.
|
|
||||||
|
|
||||||
// Use this method to prepare for the change in presentation style.
|
|
||||||
}
|
|
||||||
|
|
||||||
override func didTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
|
|
||||||
// Called after the extension transitions to a new presentation style.
|
|
||||||
|
|
||||||
// Use this method to finalize any behaviors associated with the change in presentation style.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func didResignActive(with conversation: MSConversation) {}
|
||||||
|
override func didReceive(_ message: MSMessage, conversation: MSConversation) {}
|
||||||
|
override func didStartSending(_ message: MSMessage, conversation: MSConversation) {}
|
||||||
|
override func didCancelSending(_ message: MSMessage, conversation: MSConversation) {}
|
||||||
|
override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {}
|
||||||
|
override func didTransition(to presentationStyle: MSMessagesAppPresentationStyle) {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user