How to get the full image URL on iOS with UIImagePickerController using new PHAsset stuff - uiimagepickercontroller

How the heck do you get the full image URL on iOS with UIImagePickerController using new PHAsset stuff, since the ALAssetLibrary stuff was deprecated?

I was having an awful time finding the answer to this, so to help people in the future, here is my code that works to get the actual file URL to a photo selected with the built-in iOS UIImagePickerController. Still a little nervous about using the ALAsset URL to get the PHAsset, if you know of another way to do that then by all means please share.
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL* sourceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
if (sourceURL != nil) {
PHAsset* asset = [[PHAsset fetchAssetsWithALAssetURLs:#[sourceURL] options:nil] lastObject];
PHContentEditingInputRequestOptions* assetOptions = [[PHContentEditingInputRequestOptions alloc] init];
[assetOptions setNetworkAccessAllowed:false];
[asset requestContentEditingInputWithOptions:assetOptions
completionHandler:^(PHContentEditingInput* contentEditingInput, NSDictionary* info) {
NSURL* fullImageURL = contentEditingInput.fullSizeImageURL;
printf("Hey, got the actual image URL: %s\n", [[fullImageURL absoluteString] UTF8String]);
}];
}
// ...finish and dismiss the UIImagePickerController
}

Related

Is there a way to access ALAssets information outside of resultBlock?

Okay so I have my ImagePicker all setup and the ALAssetLibrary setup to get the Picture and Title (if it exists for existing pictures or generic text for a new picture) but now I'm trying to figure out if there's a way I can access this information outside of the block call from the assetForURL method. So here's my code just so I can show what's happening (this is in the viewDidLoad method of a screen that is displayed after a picture selection is made)
__block NSString *documentName;
__block UIImage *docImage;
NSURL *resourceURL = [imageInfo objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *asset)
{
ALAssetRepresentation *imageRep = [asset defaultRepresentation];
//Get Image
CGImageRef iref = [imageRep fullResolutionImage];
//If image is null then it's a new picture from Camera
if (iref == NULL) {
docImage = [imageInfo objectForKey:UIImagePickerControllerOriginalImage];
documentName = #"New Picture";
}
else {
docImage = [UIImage imageWithCGImage:iref];
documentName = [imageRep filename];
}
};
// get the asset library and fetch the asset based on the ref url (pass in block above)
ALAssetsLibrary *imageAsset = [[ALAssetsLibrary alloc] init];
[imageAsset assetForURL:resourceURL resultBlock:resultblock failureBlock:nil];
Now I want to be able to use the two variables (documentName and docImage) elsewhere in this ViewController (for example if someone wants to change the name of the document before they save it I want to be able to revert back to the default name) but I can't seem to figure out what I need to do so these variables can be used later. Don't know if this makes much sense or not, so if I need to clarify anything else let me know.
Okay so I figured out that the problem wasn't with the code but with my logic on how I was using it. I was trying to do this on the Modal View that was presented after an image was selected instead of just doing this in the ImagePicker screen and then calling the Modal window inside of the result block code.

useLayoutToLayoutNavigationTransitions in iOS7 crash

I am building an iOS7 app and I am trying to make use of the new useLayoutToLayoutNavigationTransitions effect. I have 2 UICollectionViewControllers and when I do the following I get the transition effect
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
secondVC.useLayoutToLayoutNavigationTransitions = YES;
[self.navigationController pushViewController:secondVC animated:YES];
this works fine but what I want to do is make an api call and then in the completion block I want to push onto the nav stack like so
[webAPI getDetailsWithParams:params andCompletionBlock:^(id dict) {
//some work on the result
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
secondVC.useLayoutToLayoutNavigationTransitions = YES;
[self.navigationController pushViewController:secondVC animated:YES];
} andErrorBlock:^(NSError *error) {
}];
but this crashes every time with the following msg
-[UICollectionView _invalidateLayoutWithContext:]: message sent to deallocated instance 0x17a26400
can anyone tell me what I am doing wrong in this case? How can I get the transition effect when pushing from completion block?
EDIT: by changing it to the following I was able to transition to the second viewcontroller.
MyLayout *layout = [[MyLayout alloc] init];
SecondViewController *expandedVC = [[SecondViewController alloc] initWithCollectionViewLayout:layout];
and I also deleted the nib file that went with the file. nib file just consisted of a collection view and it was the file owners view.
While I can now transition I still do not understand why I could not do the previous nib method with in a block. So I would be grateful if someone could shed some light on it for me.
In order to use UICollectionViewController's useLayoutToLayoutNavigationTransitions to make transitions, the layout of the SecondViewController must be known. However, if you use initWithNibName:bundle: initializer, layout is not internally prepared yet, making your desired transitions impossible. As you mentioned in your edited question, you have to use [UICollectionViewController initWithCollectionViewLayout:] to initialize your second UICollectionViewController. Since your xib file has the same name as your class name, SecondViewController.xib is going to be loaded automatically by UIViewController, superclass of UICollectionViewController.
I think you were making UIKit calls from a thread that wasn't the main thread

can't see the banner on my simulator

I want to add Admob in my app, the compilation is correct, but I can not see the banner on my simulator.
The app is for iPad in landscape mode.
I added the UUID of my macbook to the variable TEST_DEVICE_ID.
Could you help me ??
Thanks
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID,
#"TEST_DEVICE_ID",
nil];
First of all, you're not actually passing the request with testDevices to AdMob. To do that, you'll want to write:
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID,
#"TEST_DEVICE_ID",
nil];
[bannerView_ loadRequest:request];
Now when you actually release, you'll want to be able to get live ads too. To find out more information, implement GADBannerViewDelegate and log why you aren't getting an ad:
- (void)adView:(GADBannerView *)view
didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"Failed to receive ad with error: %#", [error localizedFailureReason]);
}
Remember you'll need to add bannerView_.delegate = self; to set the delegate for this method to be fired.

.caf file in app not playing in iPod

In my app, i have some .caf audio file (Format: IMA 4:1, Stereo, 44.100 kHz). The problem what i m facing is that these audio file plays on button action (one button for each ringtone).They are playing fine on iphone(ios version 3 to 5 ) but im not able to listen it on ipod. I have done all the sound setting changes as solution described on other site but nothing happens.
Also ipod not stuck in headphone mode(this problem happens sometime when we plug out headphone while any audio file is playing).So please give any solution as soon as possible.
first You import framework then use below code:
#import <AudioToolbox/AudioToolbox.h>
call whenever you want by this method:
[self BackgroundSound:#"sounf file name"];//must have in resource(.wav,.mp3,.caf)
write this function by above method for call that :
- (void)BackgroundSound:(NSString *) name
{
NSString *spath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:name];
AVAudioPlayer* BackgroundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:spath] error:nil];
BackgroundPlayer.numberOfLoops = -1; // set to -1 to loop repeated
BackgroundPlayer.volume = 0.5; // value is from 0 to 1.0 (float)
[BackgroundPlayer play]; // play
}
work in iPad/iPhone both in my application. i hope ,it's help you also.

Flex mobile - click to make phone call or send an email, on iOS

Can I make a button, that when I click it the phone makes a call to a certain number, or similarly sends an email to certain address with some pre-populated fields. I need this to work on iOS and Android too.
Yes, you can make a URL request actually that the phone understands to make a call. You just prefix it with tel. Same works for "mailto".
See this example: http://www.adobe.com/devnet/air/quick_start_as/quickstarts/qs_using_uris.html
see this the exact thing you all looking for
http://www.flextechie.com/my-first-flex-mobile-application-contact-mobile-app/
you can even download the source code
Just add following code on Button Click :
-(void) makeCall
{
NSString * mobileNumber = #"+9112345678";
UIDevice *device = [UIDevice currentDevice];
if ([[device model] isEqualToString:#"iPhone"] )
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#",mobileNumber]]];
}
else
{
UIAlertView *Notpermitted=[[UIAlertView alloc] initWithTitle:nil message:#"Your device doesn't support calling feature." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[Notpermitted show];
}
}

Resources