ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

    

    // Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.

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

        

        // Within the group enumeration block, filter to enumerate just photos.

        [group setAssetsFilter:[ALAssetsFilter allPhotos]];

        

        // Chooses the photo at the last index

        [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:([group numberOfAssets] - 1)] 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];

                UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]];

                [latestPhoto resizeImageToWidth:50];

                

                if (latestPhoto){

                    [self.imgBtn setBackgroundImage:latestPhoto forState:UIControlStateNormal];

                    [self.imgBtn setBackgroundImage:latestPhoto forState:UIControlStateHighlighted];

                }

            }

        }];

    } failureBlock: ^(NSError *error) {

    }];



http://stackoverflow.com/questions/8867496/get-last-image-from-photos-app

Posted by tenn
,

카메라 관련의 주의점


AVCaptureDevice observer를 추가할 때

다른 인스턴스라고 하더라도 같이 영향을 받는 듯.

계속 크래시 하길래, 조사했더니

AVCaptureDevice에 NSKeyValueObservingOptionNew를 등록하고는 해제해주지 않은 채로,

새로운 뷰컨트롤러에서 카메라를 쓰려고 할때 같은 옵저버를 등록하려고 하자.

BAD ACCESS에러로 크래쉬.


뷰가 사라지는 지점에서 해제해주자, 현상은 없어졌다.

Posted by tenn
,


    

NSArray *array = [NSArray arrayWithObjects:@"1",@"2",@"3", nil];

    

    NSMutableArray *dataArray = [NSMutableArray arrayWithArray:array];

    [dataArray addObject:@"4"];

    

    NSArray *array2 = [NSArray arrayWithObjects:@"5",@"6",@"7", nil];

    

    [dataArray addObjectsFromArray:array2];

    

    

    for(NSString *str in dataArray){

        NSLog(@"%@", str);

    }




결과


2013-12-25 14:38:54.899 TestPrj[2030:70b] 1

2013-12-25 14:38:54.901 TestPrj[2030:70b] 2

2013-12-25 14:38:54.901 TestPrj[2030:70b] 3

2013-12-25 14:38:54.902 TestPrj[2030:70b] 4

2013-12-25 14:38:54.902 TestPrj[2030:70b] 5

2013-12-25 14:38:54.902 TestPrj[2030:70b] 6

2013-12-25 14:38:54.903 TestPrj[2030:70b] 7



Posted by tenn
,