Skip to content
Browse files

- read images from document directory (iTunes sharing supported)

- add video support
- improve messages
  • Loading branch information...
1 parent 9cd34dd commit 02e7b66b798a31eb038a5d6d95907c3ed0f5a323 @itok committed
View
3 AssetMover.xcodeproj/project.pbxproj
@@ -126,6 +126,9 @@
/* Begin PBXProject section */
577D2AEA13C104BB00DBBAFD /* Project object */ = {
isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0420;
+ };
buildConfigurationList = 577D2AED13C104BB00DBBAFD /* Build configuration list for PBXProject "AssetMover" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
View
12 AssetMover/AssetMover-Info.plist
@@ -6,6 +6,8 @@
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
+ <key>CFBundleDocumentTypes</key>
+ <array/>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
@@ -22,17 +24,27 @@
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
+ <key>CFBundleURLTypes</key>
+ <array/>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMainNibFile</key>
<string>MainWindow</string>
+ <key>UIApplicationExitsOnSuspend</key>
+ <true/>
+ <key>UIFileSharingEnabled</key>
+ <true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
+ <key>UTExportedTypeDeclarations</key>
+ <array/>
+ <key>UTImportedTypeDeclarations</key>
+ <array/>
</dict>
</plist>
View
3 AssetMover/AssetMoverAppDelegate.h
@@ -12,6 +12,9 @@
UIImageView *_imageView;
UILabel *_label;
+
+ NSMutableArray* paths;
+ NSUInteger count;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
View
75 AssetMover/AssetMoverAppDelegate.m
@@ -18,29 +18,87 @@ @implementation AssetMoverAppDelegate
@synthesize imageView = _imageView;
@synthesize label = _label;
+-(void) prepareForPath:(NSString*)path
+{
+ CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)[path pathExtension], NULL);
+ if (UTTypeConformsTo(uti, kUTTypeImage) || (UTTypeConformsTo(uti, kUTTypeMovie) && UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(path))) {
+ [paths addObject:path];
+ }
+}
+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
+ paths = [[NSMutableArray alloc] init];
+
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
+
+ NSFileManager* mgr = [[[NSFileManager alloc] init] autorelease];
+
+ // resource directory
+ NSArray* files = [mgr subpathsAtPath:[[NSBundle mainBundle] resourcePath]];
+ for (NSString* file in files) {
+ [self prepareForPath:[[NSBundle mainBundle] pathForResource:file ofType:@""]];
+ }
+
+ // document directory
+ NSString* dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
+ files = [mgr subpathsAtPath:dir];
+ for (NSString* file in files) {
+ [self prepareForPath:[dir stringByAppendingPathComponent:file]];
+ }
+
+ if ([paths count] == 0) {
+ UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"No images or videos" message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
+ [alert show];
+ [alert release];
+ return YES;
+ }
+
+ self.label.text = [NSString stringWithFormat:@"%d/%d", 0, [paths count]];
+
+ ALAssetsLibrary* library = [[[ALAssetsLibrary alloc] init] autorelease];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
- NSFileManager* mgr = [[[NSFileManager alloc] init] autorelease];
- NSArray* files = [mgr subpathsAtPath:[[NSBundle mainBundle] resourcePath]];
- __block int cnt = 0;
- for (NSString* file in files) {
- CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)[file pathExtension], NULL);
+ for (int i = 0; i < [paths count]; i++) {
+ NSString* path = [paths objectAtIndex:i];
+
+ CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)[path pathExtension], NULL);
if (UTTypeConformsTo(uti, kUTTypeImage)) {
- NSData* d = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:file ofType:@""]];
+ NSData* d = [NSData dataWithContentsOfFile:path];
dispatch_sync(dispatch_get_main_queue(), ^(void) {
self.imageView.image = [UIImage imageWithData:d];
- self.label.text = [NSString stringWithFormat:@"%d", ++cnt];
+ self.label.text = [NSString stringWithFormat:@"%d/%d", i + 1, [paths count]];
});
- [[[[ALAssetsLibrary alloc] init] autorelease] writeImageDataToSavedPhotosAlbum:d metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
+ [library writeImageDataToSavedPhotosAlbum:d metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
+ if (error) {
+ NSLog(@"%@ (%@)", [error localizedDescription], [path lastPathComponent]);
+ }
}];
+ } else if (UTTypeConformsTo(uti, kUTTypeMovie)) {
+ dispatch_sync(dispatch_get_main_queue(), ^(void) {
+ self.imageView.image = nil;
+ self.label.text = [NSString stringWithFormat:@"%d/%d", i + 1, [paths count]];
+ });
+ [library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:path] completionBlock:^(NSURL *assetURL, NSError *error) {
+ if (error) {
+ NSLog(@"%@ (%@)", [error localizedDescription], [path lastPathComponent]);
+ }
+ }];
+ }
+
+ if ([path hasPrefix:dir]) {
+ [mgr removeItemAtPath:path error:nil];
}
}
+
+ dispatch_async(dispatch_get_main_queue(), ^(void) {
+ UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Completed" message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
+ [alert show];
+ [alert release];
+ });
});
return YES;
@@ -87,6 +145,7 @@ - (void)applicationWillTerminate:(UIApplication *)application
- (void)dealloc
{
+ [paths release];
[_window release];
[_imageView release];
[_label release];
View
64 AssetMover/en.lproj/MainWindow.xib
@@ -52,7 +52,7 @@
<int key="NSvFlags">1298</int>
<string key="NSFrame">{{40, 40}, {240, 240}}</string>
<reference key="NSSuperview" ref="380026005"/>
- <reference key="NSNextKeyView"/>
+ <reference key="NSWindow"/>
<int key="IBUIContentMode">1</int>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
@@ -62,12 +62,18 @@
<int key="NSvFlags">1316</int>
<string key="NSFrame">{{40, 288}, {240, 21}}</string>
<reference key="NSSuperview" ref="380026005"/>
+ <reference key="NSWindow"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<int key="IBUIContentMode">7</int>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
- <string key="IBUIText">Label</string>
+ <string key="IBUIText"/>
+ <object class="NSFont" key="IBUIFont">
+ <string key="NSName">Helvetica</string>
+ <double key="NSSize">17</double>
+ <int key="NSfFlags">16</int>
+ </object>
<object class="NSColor" key="IBUITextColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MCAwIDAAA</bytes>
@@ -81,6 +87,7 @@
<object class="NSPSMatrix" key="NSFrameMatrix"/>
<string key="NSFrameSize">{320, 480}</string>
<reference key="NSSuperview"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="145541797"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
@@ -221,7 +228,58 @@
<nil key="sourceID"/>
<int key="maxID">13</int>
</object>
- <object class="IBClassDescriber" key="IBDocument.Classes"/>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <object class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBPartialClassDescription">
+ <string key="className">AssetMoverAppDelegate</string>
+ <string key="superclassName">NSObject</string>
+ <object class="NSMutableDictionary" key="outlets">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>imageView</string>
+ <string>label</string>
+ <string>window</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>UIImageView</string>
+ <string>UILabel</string>
+ <string>UIWindow</string>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>imageView</string>
+ <string>label</string>
+ <string>window</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBToOneOutletInfo">
+ <string key="name">imageView</string>
+ <string key="candidateClassName">UIImageView</string>
+ </object>
+ <object class="IBToOneOutletInfo">
+ <string key="name">label</string>
+ <string key="candidateClassName">UILabel</string>
+ </object>
+ <object class="IBToOneOutletInfo">
+ <string key="name">window</string>
+ <string key="candidateClassName">UIWindow</string>
+ </object>
+ </object>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/AssetMoverAppDelegate.h</string>
+ </object>
+ </object>
+ </object>
+ </object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">

0 comments on commit 02e7b66

Please sign in to comment.
Something went wrong with that request. Please try again.