diff --git a/src/library/itunes/itunesiosimporter.h b/src/library/itunes/itunesiosimporter.h index 1aec139ca08f..571490ba531e 100644 --- a/src/library/itunes/itunesiosimporter.h +++ b/src/library/itunes/itunesiosimporter.h @@ -22,4 +22,6 @@ class ITunesIOSImporter : public ITunesImporter { private: std::unique_ptr m_dao; + + void requestAuthorization(); }; diff --git a/src/library/itunes/itunesiosimporter.mm b/src/library/itunes/itunesiosimporter.mm index 60922236e1d0..8e436e0740d8 100644 --- a/src/library/itunes/itunesiosimporter.mm +++ b/src/library/itunes/itunesiosimporter.mm @@ -1,6 +1,7 @@ #include "library/itunes/itunesiosimporter.h" #import +#import #include #include @@ -176,7 +177,37 @@ void importMediaItem(MPMediaItem* item) { : ITunesImporter(pParentFeature), m_dao(std::move(dao)) { } +void ITunesIOSImporter::requestAuthorization() { + dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); + + [MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus status){ + switch (status) { + case MPMediaLibraryAuthorizationStatusAuthorized: + qInfo() << "Successfully authorized iOS media library access"; + break; + case MPMediaLibraryAuthorizationStatusRestricted: + qWarning() << "iOS media library access is restricted, Mixxx may not be able to access all tracks"; + break; + case MPMediaLibraryAuthorizationStatusDenied: + qWarning() << "iOS media library access is denied, Mixxx will not be able to access any tracks"; + break; + case MPMediaLibraryAuthorizationStatusNotDetermined: + qWarning() << "iOS media library access is not determined, Mixxx may not be able to access any tracks"; + break; + default: + qWarning() << "Unknown iOS media library authorization status:" << status; + break; + } + dispatch_semaphore_signal(semaphore); + }]; + + qInfo() << "Requesting authorization for iOS media library access..."; + dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); +} + ITunesImport ITunesIOSImporter::importLibrary() { + requestAuthorization(); + ITunesImport iTunesImport; std::unique_ptr rootItem = TreeItem::newRoot(m_pParentFeature);