0

当我的应用程序处于活动状态时,我得到最后一张图像,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];

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

4

0 回答 0