Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 停止重复将图像存储到相册中_Ios_Uiimage_Nsarray - Fatal编程技术网

Ios 停止重复将图像存储到相册中

Ios 停止重复将图像存储到相册中,ios,uiimage,nsarray,Ios,Uiimage,Nsarray,我正在将图像存储到相册中。我使用数组获取图像并存储到相册。但当我启动应用程序时,它每次都会存储。因此,图像被反复存储。如果相册中存在图像,如何停止存储图像 NSArray *photos = [NSArray arrayWithObjects: [UIImage imageNamed:@"img.jpg"], [UIImage imageNamed:@"img1.jpg"], [UI

我正在将图像存储到相册中。我使用数组获取图像并存储到相册。但当我启动应用程序时,它每次都会存储。因此,图像被反复存储。如果相册中存在图像,如何停止存储图像

NSArray *photos = [NSArray arrayWithObjects:
                   [UIImage imageNamed:@"img.jpg"],
                   [UIImage imageNamed:@"img1.jpg"],
                   [UIImage imageNamed:@"img2.jpg"],
                   nil] ;



for(int i=0; i<[photos count]; i++){


      image1=[photos objectAtIndex:i];


    NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
    BOOL isSaved=[[NSUserDefaults standardUserDefaults]boolForKey:@"photosave"];
    if (!isSaved) {
        // Save photo

        [self.library saveImage:image1 toAlbum:@"Art" withCompletionBlock:^(NSError *error) {
            //   arappdelegate.isNotSaved=FALSE;
            if (error!=nil) {
                NSLog(@"Big error: %@", [error description]);
            }
        }];
        [userDefaults setBool:YES forKey:@"photosave"];
        [userDefaults synchronize];
    }

}
NSArray*photos=[NSArray阵列包含对象:
[UIImage ImageName:@“img.jpg”],
[UIImage ImageName:@“img1.jpg”],
[UIImage ImageName:@“img2.jpg”],
零];
对于(int i=0;i
,有一种类似于在AppDelegate中使用任何布尔变量的方法。。
Appdelegate.h
@属性(非原子,读写)BOOL未保存;
Appdelegate.m
@综合保存;
-应用程序启动方法
{
isNotSaved=TRUE;
}
在你们班
-(无效)ViewDidLoad
{
appDelegate=[[UIApplication sharedApplication]委托];
}
-(无效)你的方法
{
NSArray*照片=[NSArray阵列及其对象:
[UIImage ImageName:@“img.jpg”],
[UIImage ImageName:@“img1.jpg”],
[UIImage ImageName:@“img2.jpg”],
零];
如果(appDelegate.isNotSaved)
{
对于(int i=0;i
//

-(无效)保存照片{
NSArray*照片=[NSArray阵列及其对象:
[UIImage ImageName:@“img.jpg”],
[UIImage ImageName:@“img1.jpg”],
[UIImage ImageName:@“img2.jpg”],
零];

对于(int i=0;i)您的代码不起作用..当我第一次运行它时,只保存第一个图像,然后再次运行它将所有图像保存到您应该使用的相册NSUserdefaults@Sunny沙阿:你的意思是我需要将照片数组存储到nsuserdefaults中,然后签入appdelegate?dubug在条件下检查其goign
    There is way like use any boolean variable in AppDelegate..



     Appdelegate.h
        @property(nonatomic,readwrite)BOOL isNotSaved;

        Appdelegate.m
        @synthesize isSaved;

        -applicationLaunchMethod
        {
             isNotSaved=TRUE;
        }

        in YourClass.m
        -(void)ViewDidLoad
        {
          appDelegate=[[UIApplication sharedApplication]delegate];
        }

        -(void)YourMethod
        {
        NSArray *photos = [NSArray arrayWithObjects:
                               [UIImage imageNamed:@"img.jpg"],
                               [UIImage imageNamed:@"img1.jpg"],
                               [UIImage imageNamed:@"img2.jpg"],
                               nil] ;

       if(appDelegate.isNotSaved)
    {
        for(int i=0; i<[photos count]; i++){

            image1=[photos objectAtIndex:i];

            [self.library saveImage:image1 toAlbum:@"Art" withCompletionBlock:^(NSError *error)

             {

                 if (error!=nil) {
                     NSLog(@"Big error: %@", [error description]);
                 }
             }];
        }

        appDelegate.isNotSaved=FALSE;
    }
}
NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
BOOL isSaved=[[NSUserDefaults standardUserDefaults]boolForKey:@"photosave"];
if (!isSaved) {
            [self savePhoto];
    [userDefaults setBool:YES forKey:@"photosave"];
    [userDefaults synchronize];
}
-(void)savePhoto{
NSArray *photos = [NSArray arrayWithObjects:
                   [UIImage imageNamed:@"img.jpg"],
                   [UIImage imageNamed:@"img1.jpg"],
                   [UIImage imageNamed:@"img2.jpg"],
                   nil] ;
for(int i=0; i<[photos count]; i++){
        image1=[photos objectAtIndex:i];
        [self.library saveImage:image1 toAlbum:@"Art" withCompletionBlock:^(NSError *error) {
            //   arappdelegate.isNotSaved=FALSE;
            if (error!=nil) {
                NSLog(@"Big error: %@", [error description]);
            }
        }];
    }