0

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]);
    }
}];
}
QueueOverFlow
  • 1,336
  • 5
  • 27
  • 48
  • @H2CO3 I wants to check the library created by above code is present or not programmatically, how i can check the library is present or not programmatically? – QueueOverFlow Dec 12 '12 at 11:17

1 Answers1

1

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 .

iShwar
  • 1,625
  • 1
  • 16
  • 31
  • thanks for reply, but if user manually delete the added custom library, then? – QueueOverFlow Dec 12 '12 at 11:41
  • NOTE: Don't forget to make the NSUserDefaults object as a global! – iShwar Dec 12 '12 at 11:49
  • i mean that if user delete custom library itself without using my application. So i have to check every time library exist or not when my app executed. – QueueOverFlow Dec 12 '12 at 11:52
  • have you visit http://stackoverflow.com/questions/7221167/how-to-check-if-an-alasset-still-exists-using-a-url – iShwar Dec 12 '12 at 12:21
  • Also Visit: 1) http://death-mountain.com/2011/05/alassetslibrary-and-threads/ 2) http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/Reference/Reference.html – iShwar Dec 12 '12 at 12:26