@@ -13,27 +13,33 @@ @implementation AppDelegate
1313- (BOOL )application : (UIApplication *)application
1414 didFinishLaunchingWithOptions : (NSDictionary *)launchOptions {
1515 [GeneratedPluginRegistrant registerWithRegistry: self ];
16-
17- if (@available (iOS 14 , *)) {
18- NSBundle *bundle = [NSBundle bundleForClass: [self class ]];
19- __block NSError *saveError = nil ;
20- [PHPhotoLibrary
21- requestAuthorizationForAccessLevel: PHAccessLevelAddOnly
22- handler: ^(PHAuthorizationStatus status) {
23- if (![PHPhotoLibrary.sharedPhotoLibrary
24- performChangesAndWait: ^{
25- NSURL *jpgImageTall =
26- [bundle URLForResource: @" jpgImageTall"
27- withExtension: @" jpg" ];
28- [PHAssetChangeRequest
29- creationRequestForAssetFromImageAtFileURL:
30- jpgImageTall];
31- }
32- error: &saveError]) {
33- os_log_error (OS_LOG_DEFAULT, " %@" , saveError);
34- }
35- }];
36- }
16+ if (@available (iOS 14 , *)) {
17+ // Seed the photo library with at least one image for tests to operate on.
18+ NSString *photoAddedKey = @" PhotoAdded" ;
19+ BOOL photoAdded = [NSUserDefaults .standardUserDefaults boolForKey: photoAddedKey];
20+ if (!photoAdded) {
21+ NSBundle *bundle = [NSBundle bundleForClass: [self class ]];
22+ __block NSError *saveError = nil ;
23+ [PHPhotoLibrary
24+ requestAuthorizationForAccessLevel: PHAccessLevelAddOnly
25+ handler: ^(PHAuthorizationStatus status) {
26+ if ([PHPhotoLibrary.sharedPhotoLibrary
27+ performChangesAndWait: ^{
28+ NSURL *jpgImageTall =
29+ [bundle URLForResource: @" jpgImageTall"
30+ withExtension: @" jpg" ];
31+ [PHAssetChangeRequest
32+ creationRequestForAssetFromImageAtFileURL:
33+ jpgImageTall];
34+ }
35+ error: &saveError]) {
36+ [NSUserDefaults .standardUserDefaults setBool: YES forKey: photoAddedKey];
37+ } else {
38+ os_log_error (OS_LOG_DEFAULT, " %@" , saveError);
39+ }
40+ }];
41+ }
42+ }
3743 return [super application: application didFinishLaunchingWithOptions: launchOptions];
3844}
3945
0 commit comments