QueueOverFlow
QueueOverFlow

Reputation: 1336

check the custom library present or not

I want to check whether the library is present or not. How can I check whether a library with the same name already exists?

I wants to check the library created by below code is present or not programmatically, how i can check the library is present or not programmatically?

Thanks

I use the following code for saving a custom library.

//Code for create custom library and save image

-(void)savePhoto
{
self.library = [[ALAssetsLibrary alloc] init];
[self.library addAssetsGroupAlbumWithName:@"My Library" resultBlock:nil failureBlock:nil];
[self savePhotoFinal:[UIImage imageNamed:@"tattoo1.jpg"];
}

-(void)savePhotoFinal:(UIImage *)image
{
[self.library saveImage:image toAlbum:@"My Library" withCompletionBlock:^(NSError *error) {
    if (error!=nil) {
        NSLog(@"Big error: %@", [error description]);
    }
}];
}

Upvotes: 0

Views: 152

Answers (1)

iShwar
iShwar

Reputation: 1665

When you create the custom library, and save the file in it, At the same time set a flag Using NSUserDefault, like

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 [defaults setValue:@"0" forKey:@"LIBRARYEXIST"];

and latter jus check whether the string value of this saved flag is 0 or not with

  NSString *libraryCheckStr =[defaults objectForKey:@"LIBRARYEXIST"];

if the value of string variable libraryCheckStr is found as a 0 then the library exist other wise does not exists.

When the User will delete the library manually on the action method of deleting library, set the flag to 1 for the same key LIBRARYEXIST . and further is your business logic .

Upvotes: 1

Related Questions