iOS/Sources/Extensions/NotificationContent/NotificationLoadingViewController.swift
Zac West 85b5ec4579
Support attachments which aren't downloaded in advance (#1610)
## Summary
Allows attachments to be loaded on-the-fly in the content extension if they are not present.

## Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#510

## Any other notes
- Adds `lazy` as an option to the `attachment` dictionary. When true, this prevents the attachment from being downloaded except when displayed in the content extension.  
  
This is similar, but not identical, to hide-thumbnail. Hiding the thumbnail still uses the internal storage of the notifications which are limited to e.g. 50mb. However, we'd still want to pre-load those attachments even if the thumbnail is hidden.
- Retries non-lazy attachments which failed due to a network error when the content extension opens.
2021-05-01 12:58:30 -07:00

53 lines
1.6 KiB
Swift

import Foundation
import PromiseKit
import UIKit
import UserNotificationsUI
class NotificationLoadingViewController: UIViewController, NotificationCategory {
required init(notification: UNNotification, attachmentURL: URL?) throws {
super.init(nibName: nil, bundle: nil)
}
init() {
super.init(nibName: nil, bundle: nil)
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
let activityIndicator: UIActivityIndicatorView
if #available(iOS 13, *) {
activityIndicator = UIActivityIndicatorView(style: .medium)
} else {
activityIndicator = UIActivityIndicatorView(style: .gray)
}
view.addSubview(activityIndicator)
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
activityIndicator.topAnchor.constraint(equalTo: view.topAnchor),
activityIndicator.leadingAnchor.constraint(equalTo: view.leadingAnchor),
activityIndicator.trailingAnchor.constraint(equalTo: view.trailingAnchor),
activityIndicator.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
activityIndicator.startAnimating()
}
func start() -> Promise<Void> {
.value(())
}
var mediaPlayPauseButtonType: UNNotificationContentExtensionMediaPlayPauseButtonType { .none }
var mediaPlayPauseButtonFrame: CGRect?
var mediaPlayPauseButtonTintColor: UIColor?
func mediaPlay() {}
func mediaPause() {}
}