This repository has been archived by the owner on Dec 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
to remove "My Photo Stream" from the image picker, which are difficul…
…t to be loaded from the network
- Loading branch information
Simon Xie
committed
Aug 16, 2015
1 parent
9883fdd
commit d0ba378
Showing
4 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef __ELCAlbumPickerController__REMOVE_MY_PHOTO_STREAM__H__ | ||
#define __ELCAlbumPickerController__REMOVE_MY_PHOTO_STREAM__H__ | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "ELCImagePicker/ELCAlbumPickerController.h" | ||
|
||
@interface ELCAlbumPickerController (RemoveMyPhotoStream) | ||
@end | ||
|
||
|
||
#endif |
83 changes: 83 additions & 0 deletions
83
src/wpp/qt/ELCAlbumPickerController+RemoveMyPhotoStream.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#import "ELCAlbumPickerController+RemoveMyPhotoStream.h" | ||
//#include <wpp/qt/Wpp.h> | ||
|
||
@interface ELCAlbumPickerController (RemoveMyPhotoStream) | ||
|
||
@property (nonatomic, strong) ALAssetsLibrary *library; | ||
|
||
@end | ||
|
||
@implementation ELCAlbumPickerController (RemoveMyPhotoStream) | ||
|
||
- (void)viewDidLoad | ||
{ | ||
[super viewDidLoad]; | ||
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; | ||
|
||
[self.navigationItem setTitle:NSLocalizedString(@"Loading...", nil)]; | ||
|
||
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self.parent action:@selector(cancelImagePicker)]; | ||
[self.navigationItem setRightBarButtonItem:cancelButton]; | ||
|
||
NSMutableArray *tempArray = [[NSMutableArray alloc] init]; | ||
self.assetGroups = tempArray; | ||
|
||
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init]; | ||
self.library = assetLibrary; | ||
|
||
// Load Albums into assetGroups | ||
dispatch_async(dispatch_get_main_queue(), ^ | ||
{ | ||
@autoreleasepool { | ||
|
||
// Group enumerator Block | ||
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) | ||
{ | ||
if (group == nil) { | ||
return; | ||
} | ||
|
||
// added fix for camera albums order | ||
NSString *sGroupPropertyName = (NSString *)[group valueForProperty:ALAssetsGroupPropertyName]; | ||
NSUInteger nType = [[group valueForProperty:ALAssetsGroupPropertyType] intValue]; | ||
|
||
if ([[sGroupPropertyName lowercaseString] isEqualToString:@"camera roll"] && nType == ALAssetsGroupSavedPhotos) { | ||
[self.assetGroups insertObject:group atIndex:0]; | ||
} | ||
else { | ||
[self.assetGroups addObject:group]; | ||
} | ||
|
||
// Reload albums | ||
[self performSelectorOnMainThread:@selector(reloadTableView) withObject:nil waitUntilDone:YES]; | ||
}; | ||
|
||
// Group Enumerator Failure Block | ||
void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *error) { | ||
|
||
if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusDenied) { | ||
NSString *errorMessage = NSLocalizedString(@"This app does not have access to your photos or videos. You can enable access in Privacy Settings.", nil); | ||
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Access Denied", nil) message:errorMessage delegate:nil cancelButtonTitle:NSLocalizedString(@"Ok", nil) otherButtonTitles:nil] show]; | ||
|
||
} else { | ||
NSString *errorMessage = [NSString stringWithFormat:@"Album Error: %@ - %@", [error localizedDescription], [error localizedRecoverySuggestion]]; | ||
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) message:errorMessage delegate:nil cancelButtonTitle:NSLocalizedString(@"Ok", nil) otherButtonTitles:nil] show]; | ||
} | ||
|
||
[self.navigationItem setTitle:nil]; | ||
NSLog(@"A problem occured %@", [error description]); | ||
}; | ||
|
||
// Enumerate Albums | ||
NSUInteger groupTypes = ALAssetsGroupAlbum | ALAssetsGroupEvent | ALAssetsGroupFaces | ALAssetsGroupSavedPhotos; | ||
|
||
[self.library enumerateGroupsWithTypes:groupTypes //ALAssetsGroupAll | ||
usingBlock:assetGroupEnumerator | ||
failureBlock:assetGroupEnumberatorFailure]; | ||
|
||
} | ||
}); | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters