Post

Replies

Boosts

Views

Activity

Unable to update the MPMediaItem (Lock Screen Media Controls)
I'm currently developing an app that can reproduce audio and video from the web (my own server) using SwiftUI targeting iOS15 and testing on a iPhone XS Pro Max running iOS16.2 (real device) Both the video and audio play just fine but I get this (image in the end of the post) in as the media controls. The current time and duration are correct and updated (without me calling to update them) but I'm unable to actually update the title, artist, album and artwork My first thought was to update the NowPlaying and after a lengthy search I'm yet to find a solution that works I created a small class to update the NowPlaying info import Foundation import UIKit import MediaPlayer public class MediaController {     var nowPlayingInfo = [String: Any]()     static let shared = MediaController()     private init() { }     func setupNotificationView(title: String?, album: String?, artist: String?, thumbnailUrl: String) {         nowPlayingInfo = [String : Any]()         nowPlayingInfo[MPMediaItemPropertyTitle] = title         nowPlayingInfo[MPMediaItemPropertyAlbumTitle] = album         nowPlayingInfo[MPMediaItemPropertyArtist] = artist MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo     } } The NowPlaying still doesn't update This is the call sequence when I press play let avAsset = AVURLAsset(url: URL(string: "https://domain.com/video.mp4") let avItem = AVPlayerItem(asset: avAsset) player.replaceCurrentItem(with: avItem) do { try AVAudioSession.sharedInstance().setActive(true); } catch { print(error) } player.play() MediaController.shared.setupNotificationView(title: "A Title", album: "A Album", artist: "A Artist", thumbnailUrl: "") Although the app is being developed using SwiftUI I'm using the UIViewControllerRepresentable to display a the video using AVPlayerViewController since the current one misses the PiP and under makeUIViewController I have the following code let controller = AVPlayerViewController() controller.player = player controller.allowsPictureInPicturePlayback = true controller.entersFullScreenWhenPlaybackBegins = true controller.delegate = context.coordinator and on the app launch I have the following let audioSession = AVAudioSession.sharedInstance() do { try audioSession.setCategory(AVAudioSession.Category.playback) } catch { print("Setting category to AVAudioSessionCategoryPlayback failed.") } And yes I have the background mode capability enabled for "Audio, AirPlay and Picture in Picture" I'm at a lost here and hope someone can help.
2
0
1.5k
Dec ’22
CoreData+CloudKit custom Zone
Hi, I'm using CoreData+CloudKit in a blank universal project for macOS 11 and iOS14. The records are in a private database inside a custom zone, I was able to set the correct database, but I'm yet to be able to set the zone. On the PersistentController created by default by Xcode 12 I have the following code let container: NSPersistentCloudKitContainer     init(inMemory: Bool = false) {         container = NSPersistentCloudKitContainer(name: "finances_manager_pro")         let customZone = CKRecordZone(zoneName: "CloudCore")         guard let description = container.persistentStoreDescriptions.first else {             fatalError("Error")         }         description.cloudKitContainerOptions?.databaseScope = .private         if inMemory {             container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")         }         container.loadPersistentStores(completionHandler: { (storeDescription, error) in             if let error = error as NSError? {                 fatalError("Unresolved error \(error), \(error.userInfo)")             }         })     } And inside a View @FetchRequest(         sortDescriptors: [NSSortDescriptor(keyPath: \ExpenseCoreData.timestamp, ascending: true)],         animation: .default)     private var items: FetchedResults<ExpenseCoreData> I've searched around the web and in apple docs but I haven't found an updated way to do this.
2
0
1.7k
Nov ’20
Sharing a file using UIDocumentInteractionController
HiI'm trying to share a PDF file stored on the phone using the UIDocumentInteractionControllerBut even though the menu appears with all the options none of them work. I think I was able to provide a bit of more information when I tried to use the AirDrop. I got a debug message saying "The transferer faild because there are no valid files to send" (this is a rough translation, the message was localized)I have the following codeextension ExportedReportsTableViewController: UIDocumentInteractionControllerDelegate { func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController { return self } func shareFile(filePath: String, loc: CGRect) { let stripPath = filePath.components(separatedBy: "/") let fileName = stripPath[stripPath.count - 1] let timestamp = fileName.replacingOccurrences(of: "Report", with: "").replacingOccurrences(of: ".pdf", with: "") let newFileName = Date(ticks: Double(timestamp)!).toString(format: "dd MMMM yyyy HH:mm") let nsURL = NSURL.fileURL(withPath: filePath) let url = nsURL as URL let dic = UIDocumentInteractionController(url: url.absoluteURL) dic.uti = "com.adobe.pdf" dic.delegate = self dic.name = newFileName //dic.presentPreview(animated: true) <-- It works perfectly dic.presentOptionsMenu(from: loc, in: self.view, animated: true) } }If I use the (presentPreview) method it works perfectly (even the share inside that controller) but with the presentOptionsMenu method it fails to send (the menu appears)I can only assume that's a function for the delegate? The url is valid (it works on the preview)Any ideas?BTW it's possible, when sending change the file name?For example the file name is "Report082182414.pdf" and when sent it appears "17 July 2017.pdf" (I know a work arround but requires copying the file with a new name and I wanted to avoid that)Thanks in advancePedro Cavaleiro
5
0
7.3k
Jul ’17
Access to Shared iOS Keychain with WatchOS
Hi,I'm crurently unable to access my app keychain after a long search these are the steps that I've tryed so farFirst of All I'm running on "real" devices not in simulators1. Key chain is enabled for a group, in here I will go for this group "appbundle.sharedkeychain" and the app prefix I'll say that's "1A2B3C4D5E"2. The keychain code is currently implemented on a Framework3. The Framework is a Pod that I've downloaded and tweaked so that worked with a shared keychain witch so far I was unable to.So I created a variable called kSAAGroup witch contains the following string "1A2B3C4D5E.appbundle.sharedkeychain"In the addKeychainFunction I have the following codeprivate func addKeychainItem(withAttributes attributes: [String: AnyObject]) throws -> Data { var mutableAttributes = attributes mutableAttributes[kSecClass as String] = kSecClassGenericPassword mutableAttributes[kSecReturnPersistentRef as String] = kCFBooleanTrue mutableAttributes[kSecAttrSynchronizable as String] = kCFBooleanTrue mutableAttributes[kSecAttrAccessible as String] = kSecAttrAccessibleAlways mutableAttributes[kSecAttrAccessGroup as String] = kSAAGroup as AnyObject? / / if mutableAttributes[kSecAttrAccount as String] == nil { mutableAttributes[kSecAttrAccount as String] = UUID().uuidString as NSString } var result: AnyObject? let resultCode: OSStatus = withUnsafeMutablePointer(to: &result) { SecItemAdd(mutableAttributes as CFDictionary, $0) } guard resultCode == errSecSuccess else { throw Keychain.Error.systemError(resultCode) } guard let persistentRef = result as? Data else { throw Keychain.Error.incorrectReturnType } return persistentRef }And to retrieve all the keychain itemsprivate func allKeychainItems() throws -> [NSDictionary] { let queryDict: [String : AnyObject] = [ kSecClass as String: kSecClassGenericPassword, kSecMatchLimit as String: kSecMatchLimitAll, kSecReturnPersistentRef as String: kCFBooleanTrue, kSecReturnAttributes as String: kCFBooleanTrue, kSecReturnData as String: kCFBooleanTrue, kSecAttrSynchronizable as String: kCFBooleanTrue, kSecAttrAccessible as String: kSecAttrAccessibleAlways, kSecAttrAccessGroup as String: kSAAGroup as AnyObject, ] var result: AnyObject? let resultCode = withUnsafeMutablePointer(to: &result) { SecItemCopyMatching(queryDict as CFDictionary, $0) } if resultCode == errSecItemNotFound { / return [] } guard resultCode == errSecSuccess else { throw Keychain.Error.systemError(resultCode) } guard let keychainItems = result as? [NSDictionary] else { throw Keychain.Error.incorrectReturnType } return keychainItems }I add the item to the keychain on the iPhone and if I close the app and reopen all the items are still there, so I assume everything it's working on the local level, I can add, delete, update and fetch all items.Now on the watchOS I get nothing, as if the keychain is empty.Any ideas?
10
1
5.3k
Jun ’17