关闭iphone中的App NSTimer更新后

时间:2013-07-03 06:41:16

标签: objective-c xcode nstimer

当我的应用激活后,我会从ALAssetsLibrary获取存储在sqlite中的最后一张图片,然后我开始NSTimer检查新图片是否已添加到ALAssetsLibrary。在我的应用程序中截取屏幕截图后,它会显示警报,因为sqlite中的图像名称和ALAssetsLibrary最后一个图像名称不匹配。当应用程序关闭时我停止计时器,用户再次打开它我再次启动计时器检查截图图像是否被删除。如果未删除,则会显示警告

-(void)getAllImagesName
{
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

    NSMutableArray *imgArray = [[NSMutableArray alloc]init];

    [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

        // Within the group enumeration block, filter to enumerate just photos.
        [group setAssetsFilter:[ALAssetsFilter allPhotos]];

            for (int i=0; i<[group numberOfAssets]; i++) {

                // Chooses the photo at the last index
                [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:i] options:0 usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {

                    // The end of the enumeration is signaled by asset == nil.
                    if (alAsset) {
//                        ALAssetRepresentation *representation = [alAsset defaultRepresentation];


                        [imgArray addObject:alAsset.defaultRepresentation.filename];


                    }
                }];
            }

            NSString *img;
            img=[[DBModel database]getPreviousName];
            NSLog(@"select img=%@",img);
            NSArray *results;

                NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@",img];
                results = [contentArray filteredArrayUsingPredicate:predicate];
                //NSLog(@"predicate results = %@",results);

            if ([results count] != 0) {

                    [self displayAlertMsg];


            }
            else{

            }

        }

    } failureBlock: ^(NSError *error) {
        // Typically you should handle an error more gracefully than this.
        //NSLog(@"No groups");
    }];

}



timer1 = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(getAllImagesName) userInfo:nil repeats:YES];
    runLoop = [NSRunLoop currentRunLoop];
    [runLoop addTimer:timer1 forMode:NSRunLoopCommonModes];
    [runLoop run];

我的问题是用户在其他应用程序中拍摄屏幕并尝试使用我的应用程序后显示警报。关闭app后计时器是否正在运行?请让我知道任何不理解我的问题的人。

0 个答案:

没有答案