Created
November 23, 2011 07:35
-
-
Save nicwise/1388120 to your computer and use it in GitHub Desktop.
using ALAssetLibrary
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
public partial class AppDelegate : UIApplicationDelegate | |
{ | |
// class-level declarations | |
UIWindow window; | |
OwenViewController viewController; | |
ALAssetsLibrary lib; | |
UIImage image; | |
NSDictionary dict = new NSDictionary (); | |
// | |
// This method is invoked when the application has loaded and is ready to run. In this | |
// method you should instantiate the window, load the UI into it and then make the window | |
// visible. | |
// | |
// You have 17 seconds to return from this method, or iOS will terminate your application. | |
// | |
public override bool FinishedLaunching (UIApplication app, NSDictionary options) | |
{ | |
window = new UIWindow (UIScreen.MainScreen.Bounds); | |
viewController = new OwenViewController (); | |
window.RootViewController = viewController; | |
window.MakeKeyAndVisible (); | |
lib = new ALAssetsLibrary (); | |
//this is embedded into my app - just set to "content" | |
image = UIImage.FromFile ("armbears.jpg"); | |
lib.WriteImageToSavedPhotosAlbum (image.AsJPEG (), dict, delegate(NSUrl assetUrl, NSError error) { | |
if (error != null) | |
{ | |
Console.WriteLine (error.LocalizedDescription); | |
} | |
Console.WriteLine ("WRITE: >>>" + assetUrl); | |
}); | |
//this is all async, so you are seldom going to see the image you put in, come out right away. | |
lib.Enumerate (ALAssetsGroupType.All, (ALAssetsGroup @group, ref bool stop) => { | |
if (group != null) | |
{ | |
stop = false; | |
group.SetAssetsFilter (ALAssetsFilter.AllAssets); | |
group.Enumerate ((ALAsset asset, int index, ref bool stop2) => | |
{ | |
if (asset != null) | |
{ | |
stop2 = false; | |
Console.WriteLine ("ENUMERATE Asset: " + asset.DefaultRepresentation.Url); | |
} | |
} | |
); | |
} | |
}, (error) => { | |
Console.WriteLine ("Error?"); | |
if (error != null) | |
{ | |
Console.WriteLine ("Error!" + error.LocalizedDescription); | |
} | |
}); | |
//you wanna change this... look in the debug log for URLs | |
string testUrl = "assets-library://asset/asset.JPG?id=069817D9-2412-4C26-923B-BA6DC745D541&ext=JPG"; | |
lib.AssetForUrl (new NSUrl (testUrl), (asset) => { | |
Console.WriteLine ("Read asset back"); | |
if (asset != null) | |
{ | |
Console.WriteLine ("{0} - {1}", asset.DefaultRepresentation.Filename, asset.AssetType); | |
} | |
}, (error) => { | |
Console.WriteLine ("error?"); | |
if (error != null) | |
{ | |
Console.WriteLine ("Error: " + error.LocalizedDescription); | |
} | |
}); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment