How access iPod Library in my iPhone app, like to the user listem music when is playing... like in the gameloft games, or the slide show from the Photos.app ?
Look at MPMusicPlayerController. I read it can access the iPod library. I never used it, and I don't know if it can help you...
- (void)addMusicBtnAction{
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
mediaPicker.delegate = self;
//mediaPicker.prompt = #"Select Audio";
mediaPicker.prompt = NSLocalizedString (#"Select any song from the list", #"Prompt to user to choose some songs to play");
for (UIWindow* window in [UIApplication sharedApplication].windows) {
NSArray* subviews = window.subviews;
if ([subviews count] > 0)
for (UIAlertView *alrt in subviews) {
if ([alrt isKindOfClass:[UIAlertView class]]){
if (alrt.tag == 10020) {
[alrt dismissWithClickedButtonIndex:0 animated:YES];
}
}
}
}
[self presentModalViewController:mediaPicker animated:YES];
//[mediaPicker release];
}
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
NSArray * SelectedSong = [mediaItemCollection items];
if([SelectedSong count]>0){
MPMediaItem * SongItem = [SelectedSong objectAtIndex:0];
NSURL *SongURL = [SongItem valueForProperty: MPMediaItemPropertyAssetURL];
NSString *str = [NSString stringWithFormat:#"%#",SongURL];
appDelegate.musicFilePath = str;
//NSLog(#"Audio Loaded");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Success!" message:#"Your audio has been selected" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil, nil];
alert.tag = 78787878;
[alert show];
// [alert release];
}
[self dismissModalViewControllerAnimated: YES];
}
// Responds to the user tapping done having chosen no music.
- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker {
[self dismissModalViewControllerAnimated: YES];
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque animated:YES];
}
Related
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Hi I am trying to have 4 buttons and each of them have different alerts when pressed. I am running into an issue, I had 3 buttons and I decided to add a "Rate My App" Button but now it isnt' working, please help me. (By the way the error is Expexted Exspression)(Org.=Organization (Fixed in App), Email- Real email in app,
#define TAG_Band 1
#define TAG_DEV 2
#define TAG_EDEV 3
#define TAG_RATE 4
#interface Org.ContactInfo () <MFMailComposeViewControllerDelegate>
#end
#implementation Org.ContactInfo:UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Contacts";
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)ContactBand:(id)sender;{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Contact the Band" message:#"Contact the Org. or go to their website!" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Visit the Org. Website",#"E-Mail The Org. President", #"E-Mail The Org. Treasurer", nil];
alert.tag = TAG_Band;
[alert show];
}
-(IBAction)ContactDev:(id)sender;{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Contact Me" message:#"Contact Me on Features you would like me to consider! I will do my Best to look at all of the Suggestions!" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Visit My Website",#"E-Mail Me!", nil];
alert.tag = TAG_DEV;
[alert show];
}
-(IBAction)RateMyApp:(id)sender;{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Rate My App" message:#"When Your Reviewing my App, Please remember that this app was at no cost to the Mighty Mustang Band." delegate:self cancelButtonTitle:#"Not Right Now" otherButtonTitles:#"Rate My App!!", nil];
alert.tag = TAG_RATE;
[alert show];
}
-(IBAction)AppInfo:(id)sender;{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Version 1.0" message:#"More Updates Coming Soon. Please Feel Free to E-Mail me on features that you would like me to consider" delegate:self cancelButtonTitle:#"Not Right Now" otherButtonTitles:#"Email-Me", nil];
alert.tag = TAG_EDEV;
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView.tag == TAG_Band){
if (buttonIndex==1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://URL.org"]];
}
else if (buttonIndex==2){
//Subject
NSString *emailTitle = #"";
//Recipients
NSString *emailBody=#"Org. President";
NSArray *toRecipients = [NSArray arrayWithObject:#"Person#Org.org"];
MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setSubject:emailBody];
[mc setToRecipients:toRecipients];
[self presentViewController:mc animated:YES completion:NULL];
}
else if (buttonIndex==3){
//Subject
NSString *emailTitle = #"";
//Recipients
NSString *emailBody=#"Org. Treasurer, ";
NSArray *toRecipients = [NSArray arrayWithObject:#"Person#Org.org"];
MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setSubject:emailBody];
[mc setToRecipients:toRecipients];
[self presentViewController:mc animated:YES completion:NULL];
}
}
else if (alertView.tag == TAG_DEV){
if (buttonIndex==1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://stepheniosdeveloper.wordpress.com"]];
}
else if (buttonIndex==2){
NSString *emailTitle = #"";
//Recipients
NSString *emailBody=#"";
NSArray *toRecipients = [NSArray arrayWithObject:#"Email#gmail.com"];
MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setSubject:emailBody];
[mc setToRecipients:toRecipients];
[self presentViewController:mc animated:YES completion:NULL];
}
}
else if (alertView.tag == TAG_EDEV);{
if (buttonIndex==1){
NSString *emailTitle = #"";
//Recipients
NSString *emailBody=#"";
NSArray *toRecipients = [NSArray arrayWithObject:#"Email#gmail.com"];
MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setSubject:emailBody];
[mc setToRecipients:toRecipients];
[self presentViewController:mc animated:YES completion:NULL];
}
}
else if (alertView.tag == TAG_RATE);{ //Expected Expression
if (buttonIndex==1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://itunes.apple.com/us/app/Org/id607257427?ls=1&mt=8"]];
}
}
}
It worked Before I added the last on (TAG_RATE) but now I don't understand why it isn't working anymore. Please Help.
There is a typo in your code: you have extra ; after the last two else if conditions:
else if (alertView.tag == TAG_EDEV)/*;*/{ // extra `;`
//...
}
else if (alertView.tag == TAG_RATE)/*;*/{ // extra `;` //Expected Expression
// ...
}
I want to make an overlay on camera of my iphone app.I have followed this tutorial
But it teaches about capturing the image,I need to implement it on recording the video.
In the tutorial it is simply
- (void)takePicture
{
[picker takePicture];
}
But I am not able to implement it on recording the video,Please help me with an example if you can
Now without overlay I am using this coding for recording the video[I wish to implement it with the above tutorial]
-(void)ViewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(onUploadVideoProgress:) name:#"UPLOADPROGRESS" object:nil];
self.mediaTypes=[NSArray arrayWithObjects:(NSString *) kUTTypeMovie,nil];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
videoRecorder = [[UIImagePickerController alloc] init];
videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
videoRecorder.delegate = self;
NSArray *mediaTypes1 = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
NSArray *videoMediaTypesOnly = [mediaTypes1 filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"(SELF contains %#)", #"movie"]];
if ([videoMediaTypesOnly count] == 0)
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Sorry but your device does not support video recording"
delegate:nil
cancelButtonTitle:#"OK"
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet showInView:[[self view] window]];
}
else
{
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
videoRecorder.cameraDevice = UIImagePickerControllerCameraDeviceRear;
videoRecorder.mediaTypes = videoMediaTypesOnly;
videoRecorder.videoQuality = UIImagePickerControllerQualityType640x480;
videoRecorder.videoMaximumDuration = 30.0f;
appDelegate.videoOrientation = #"portrait";
[self presentModalViewController:videoRecorder animated:YES];
}
}
else
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Sorry but your device does not support video recording"
delegate:nil
cancelButtonTitle:#"OK"
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet showInView:[[self view] window]];
}
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.videoURL=[[info objectForKey:UIImagePickerControllerMediaURL] path];
self.videoData=[NSData dataWithContentsOfURL:[info objectForKey:UIImagePickerControllerMediaURL]];
[self dismissModalViewControllerAnimated:YES];
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType compare:(NSString*)kUTTypeMovie] == NSOrderedSame) {
NSURL *mediaUrl = [info objectForKey:UIImagePickerControllerMediaURL];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:mediaUrl];
moviePlayer.shouldAutoplay=NO;
UIImage *thumbnail = [moviePlayer thumbnailImageAtTime:0.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
appDelegate.selectedVideo=[NSDictionary dictionaryWithObjectsAndKeys:
self.videoURL,#"videourl",
self.videoData,#"videodata",
thumbnail,#"thumbdata",
nil ];
}
AddOrEditVideoDetails *controller = [[AddOrEditVideoDetails alloc]initWithNibName:#"AddOrEditVideoView"bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];
}
UIImagePickerController already has API for recording video. You can call
– startVideoCapture
– stopVideoCapture
to record video. Check the API
i display route from start to end point in mapView in iphone and i done it.But after one day i open this project and it does not display route because UICGDirectionsDelegate functions are not called. I dont know why its happen kindly some body guide me about this problem.Many thanks and my sample code is here`
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
if (diretions.isInitialized) {
[self update];
}
routeOverlayView = [[UICRouteOverlayMapView alloc] initWithMapView:mapViews];
diretions = [UICGDirections sharedDirections];
diretions.delegate = self;
}
- (IBAction)backButton:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)update {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
UICGDirectionsOptions *options = [[UICGDirectionsOptions alloc] init];
options.travelMode = travelMode;
if (is_route) {
startPoint = [NSString stringWithFormat:#"%f,%f",APPDELEGATE.user_latitude,APPDELEGATE.user_longitude];
endPoint = [NSString stringWithFormat:#"%#,%#",routeObj.latitude,routeObj.longitude];
destination = poiObj.english_title;
}else {
startPoint = [NSString stringWithFormat:#"%f,%f",APPDELEGATE.user_latitude,APPDELEGATE.user_longitude];
endPoint = [NSString stringWithFormat:#"%# ,%#",poiObj.latitude,poiObj.longitude];
destination = routeObj.starting_poi_name;
}
[diretions loadWithStartPoint:startPoint endPoint:endPoint options:options];
}
- (void)moveToCurrentLocation:(id)sender {
[mapViews setCenterCoordinate:[mapViews.userLocation coordinate] animated:YES];
}
- (void)addPinAnnotation:(id)sender {
UICRouteAnnotation *pinAnnotation = [[UICRouteAnnotation alloc] initWithCoordinate:[mapViews centerCoordinate]
title:nil
annotationType:UICRouteAnnotationTypeWayPoint];
[mapViews addAnnotation:pinAnnotation];
}
#pragma mark <UICGDirectionsDelegate> Methods
- (void)directionsDidFinishInitialize:(UICGDirections *)directions {
[self update];
}
- (void)directions:(UICGDirections *)directions didFailInitializeWithError:(NSError *)error {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Map Directions" message:[error localizedFailureReason] delegate:nil cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alertView show];
}
- (void)directionsDidUpdateDirections:(UICGDirections *)directions {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
// Overlay polylines
UICGPolyline *polyline = [directions polyline];
NSArray *routePoints = [polyline routePoints];
[routeOverlayView setRoutes:routePoints];
// Add annotations
currentLocation = #"You are here";
UICRouteAnnotation *startAnnotation = [[UICRouteAnnotation alloc] initWithCoordinate:[[routePoints objectAtIndex:0] coordinate]
title:currentLocation
annotationType:UICRouteAnnotationTypeStart];
UICRouteAnnotation *endAnnotation = [[UICRouteAnnotation alloc] initWithCoordinate:[[routePoints lastObject] coordinate]
title:destination
annotationType:UICRouteAnnotationTypeEnd];
[mapViews addAnnotations:[NSArray arrayWithObjects:startAnnotation, endAnnotation, nil]];
}
- (void)directions:(UICGDirections *)directions didFailWithMessage:(NSString *)message {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Map Directions" message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alertView show];
}
`
In UICGRoute.m
Replace this
NSArray *stepDics;
NSDictionary *k;
for (int i = 0; i<allKeys.count; i++) {
k = [dictionaryRepresentation objectForKey:[allKeys objectAtIndex:i]];
if ([k objectForKey:#"Steps"]) {
stepDics = [k objectForKey:#"Steps"];
break;
}
}
with
NSDictionary *k = [dictionaryRepresentation objectForKey:[allKeys objectAtIndex:[allKeys count] - 1]];
NSArray *stepDics = [k objectForKey:#"Steps"];
I am having awkward problem in using the ios camera from a action sheet: When the user touches the "picture button" an action sheet shows up with two options (to use a photo from the photo library or to take a picture with the camera).
Whatever option I choose, nothing happens, but when I select the media type again, it works.
Bellow is my code:
- (IBAction)selectMediaType: (id)sender {
[appDelegate hideTabBar];
UIActionSheet *action = [[UIActionSheet alloc]
initWithTitle: nil
delegate:self
cancelButtonTitle:#"Fechar"
destructiveButtonTitle: nil
otherButtonTitles:#"Galeria", #"Tirar Foto", nil];
[action showFromTabBar: appDelegate.tabController.tabBar];
}
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
NSArray *mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
imagePicker.delegate = self;
imagePicker.hidesBottomBarWhenPushed = YES;
imagePicker.mediaTypes = mediaTypes;
imagePicker.allowsEditing = NO;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
imagePicker.hidesBottomBarWhenPushed = YES;
} else if (buttonIndex == 1) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
NSArray *mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
imagePicker.delegate = self;
imagePicker.mediaTypes = mediaTypes;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
[self presentModalViewController:imagePicker animated:YES];
} else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#""
message:#"Your device does not support this feature!"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}
} else {
[appDelegate showTabBar];
}
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image;
NSURL *mediaURL;
mediaURL = (NSURL *) [info valueForKey:UIImagePickerControllerMediaURL];
if (mediaURL == nil) {
image = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage];
}
imageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
[appDelegate showTabBar];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
[appDelegate showTabBar];
}
Could anyone help me with this?
Thanks.
I got it.
Basically it was a memory leak issue: I was switching views adding subviews in the super view (not in the current view) but I was not removing the old one from the super view, so I got a memory leak ;)
I use the MFMessageComposeViewController for sending in App sms. in iPhone 4.0, if there is no SIM card, the app exits. it just gives a pop up message "no sim card installed".
The delegate callback MessageComposeResultSent. But application exits. Is there any way to prevent it from exiting? or how to check if there is any SIM card in the phone?
Code snippets below:
/* Open the system sms service, copying the sms text in system clipboard. */
- (void) sendSMSAsURLRequest {
NSString *phoneNumber = friend.phoneMobile;
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
NSString *textUTIType = (NSString *)kUTTypeUTF8PlainText; // add MobileCoreServices.framework for this type.
[pasteBoard setValue:[self buildSMSText] forPasteboardType:textUTIType];
NSString *urlString = [NSString stringWithFormat:#"sms:%#", phoneNumber];
NSURL *url = [[NSURL alloc] initWithString: urlString];
[[UIApplication sharedApplication] openURL: url];
[url release];
}
-(void) sendInAppSMS {
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
controller.delegate = self;
if([MFMessageComposeViewController canSendText])
{
NSString *smsText = [self buildSMSText];
controller.body = smsText;
controller.recipients = [NSArray arrayWithObjects:friend.phoneMobile, nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultCancelled:
NSLog(#"Cancelled");
break;
case MessageComposeResultFailed:{
NSString *alertString = NSLocalizedString(#"Unknown Error. Failed to send message", #"");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:alertString delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[alert release];
break;
}
case MessageComposeResultSent:
NSLog(#"SMS sent");
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
To Detect Sim Card is installed or not use following Code :
#import CoreTelephony;
CTTelephonyNetworkInfo *networkInfo = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
if (!carrier.isoCountryCode) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"No SIM Card Installed" message:nil delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
else{
//Paste Your code here
}
The work around I am using now is, a flag in the app delegate,
- (void)applicationWillResignActive:(UIApplication *)aNotification {
if (shouldExitApp) {
exit(0);
}
}
In the SMS sending view controller,
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
((LuupAppDelegate *)[[UIApplication sharedApplication] delegate]).shouldExitApp = NO;
And set the flag again, when in the SMS sending view controller,
- (void) viewDidAppear:(BOOL)animated {
((LuupAppDelegate *)[[UIApplication sharedApplication] delegate]).shouldExitApp = YES;
[super viewDidAppear:animated];
}