I want to dial a number from IPhone simulator for India. I have tried this on a button click:
-(void)makeaCall
{
NSURL *phoneNumber = [[NSURL alloc] initWithString: #"tel:1-800-180-2222"];
[[UIApplication sharedApplication] openURL: phoneNumber];
}
But it's not showing any action of dialing any number.
Please help me with this.
you can't make a phone call from the simulator you will need a real phone for that.
but you can simulate an incoming call by selecting Hardware > Toggle In-Call Status Bar. also the incoming call should trigger in the app delegate the method applicationWillResignActive.
You might have to try that on a real phone, the simulator is a simulator after all and might not be able to make calls.
Related
Okay guys i have a problem. I'm stream MPMoviePlayerController and i want it to play audio in background and i've somewhat achieved this.
This is what i do in my -didFinishLaunchingWithOptions:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:YES error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
Now whenever the application calls -applicationWillResignActive:
i do a post notification to continue the playback. And this works but it's an ugly fix. As there is a second delay between the sound stopping and the notification being called. So the playback stops for a second and then continues again by calling the notification which just says [viewPlayer play];
And many other have achieved smooth background playback. Like spotify or other apps whenever you enter background mode there is no sound lag/clipping in sound. This is really annoying to listen to whenever i press the home button or lock the phone.
Yes i did set the background mode for playback.
I have also tried -applicationDidEnterBackground: but this notification is even slower. It comes after -applicationWillResignActive:
I have no idea how to fix this, and or how others achieved it. I have looked through almost all other similar questions. None have my problem.
Thanks in advance.
I've recently used a framework to stream YouTube video inline in a UIView. This framework has a category on MPMoviePlayerController which works pretty well. You notice a change in the music when going to background but it is still acceptable.
The category can be found here:
MPMoviePlayerController+BackgroundPlayback.h
MPMoviePlayerController+BackgroundPlayback.m
I would like to test how my app behaves when the app is quit and the user taps a notification in notification center so that my app is launched. In - didFinishLaunchingWithOptions you can check for the key UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; but how can I debug this?
If i start running the app in Xcode then I quit the app it will lose the connection to Xcode.
If you set your Xcode Scheme to launched manually (Edit Scheme > Run > Info), then you can stop running your app after you've scheduled your UILocalNotification.
Then if you run your application again, it won't launch until you launch it from the simulator/device.
Then you could wait for the notification to fire and click the notification which then launches your app (manually!). That way you can debug that UILocalNotification from the launchOptions of application:didFinishLaunchingWithOptions:
Just note that for debugging, you'll probably want to schedule your UILocalNotification for a date about 10 seconds or so in the future, it's always a pain to debug time related stuff.
Good luck.
the didFinishLaunchingWithOptions: method will not be called until you launch the app. But closing your app does NOT make your app loses its connection with xcode, as your app goes in background.
Maybe i missed something, but you actually can run your app in your device and then proceed as you wish.
Also you can try this code in didFinishLaunchingWithOptions: if the log are still not working.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"options" message:[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey] description] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
return YES;
Keep your application running in background connected to xcode in debug mode and let one local notification arrive, then go to notification center and click on that notification and didReceiveLocalNotification: function will be called.
The only difference between local notification arriving when application is completely closed is that you have to write code in didFinishLaunchingWithOptions (you can copy paste same code you have written for didReceiveLocalNotification: function) and didReceiveLocalNotification: is not called.
Hope this info helps you..
May be this is a stupid answer. :)
I usually put a UIAlertView there. And set the text in alertview depending on the local notification.
Another is quit the app. Put some NSLog's in applicationDidFinishLaunching. Quit the App. Go to Xcode->Organiser. Then select your device under Devices tab. Select the options Console. You can see the logs there.
Hope this may help.
I across the following code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://8005551212"]];
on : Making phone calls on iPhone
But, it does not work for me in the simulator.
I have connected the IBAction(callphone) to the ViewController(TouchUpInside). I am now not sure, is it because I am checking my code in simulator? I do not get a dialog box. Please advice.
I tried putting log statements and the action does get called since the log stamtments that I wrote to test is being printed
Can you make a phone call from your Mac? No. That's why the simulator doesn't work when you try to open a tel:// URL. You must do this from a device that can make a call: an iPhone, but not an iPad or iPod touch.
I am creating a non appstore jailbreak tweak and I came across a problem that causes my app to crash.
I am using musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
the music player has complete functionality, play/pause, next, previous. it displays the title of the song, the artist, the artwork and everything.
the problem seems to be the loading and unloading of the musicplayer.
for example, if i am running the app, and i close the iphone's Music app, it will cause my app to crash. also if i load the app without the Music app running in the background it will crash.
as long as the music app is running in the background my app will not crash.
can anyone help me with this?
is something to be set to nil? or how do i go about releasing them?
should they be synthesize/property?
I was having this problem also for my tweak, and I couldn't figure out a way to fix it. I ended up using the AVPlayer Method, It seems to work well for me. Granted I only need to play one song, so if you need to play a playlist of some sorts you are out of luck.
I used it like the following in the mediapickerclass:
NSURL *url = [[mediaItemCollection.items objectAtIndex: 0] valueForProperty:MPMediaItemPropertyAssetURL]
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url];
AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
[player play];
If you need you need to reference it from somewhere else you can just write the url to a .plist
I'm writing an app where I want the user to be able to get directions. I know about the google API, and I have that implemented, but I was wondering about ways to jump directly to the native Maps app and give the user directions instead. I think I've seen it done before, but I could be mistaken.
Any help is much appreciated.
You can open the maps app by using regular URL that points to Google Maps. From the Apple URL Scheme reference:
The maps URL scheme is used to show geographical locations and to generate driving directions between two points. If your application includes address or location information, you can use map links to forward that information to the Maps application on iOS and the Google Maps website on other platforms.
Unlike some schemes, map URLs do not start with a “maps” scheme identifier. Instead, map links are specified as regular http links but are targeted at the Google Maps servers. The following examples show the strings you would use in Safari and in a native application to show a map of the city of Cupertino, California.
HTML link:
Cupertino
Note that on a device that does not have maps installed (not sure if those even exist), the link will open in a regular browser, since it is simply an HTTP link.
To open the URL, you can present the link in a UIWebView, or you can use code to open it. for example:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://maps.google.com/maps?q=Cupertino"]];
If you wanted to pass in a custom location and open it when the user taps a button, you can make a method like this:
- (IBAction) openMapsAppAndShowLocation:(NSString *)locationToShow{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://maps.google.com/maps?q=%#", locationToShow]]];
}
If you wanted, you could refactor the method to take latitude/longitude pair too. That might look like this:
- (IBAction) openMapsAppAndShowLatitude:(double)latitude andLongitude:(double)longitude{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://maps.google.com/maps?q=\"%f,%f\"", latitide, longitude]]];
}
You can use either this:
NSString *latlong = #"-56.568545,1.256281";
NSString *url = [NSString stringWithFormat: #"http://maps.google.com/maps?ll=%#",
[latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
this,
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString: #"http://maps.google.com/maps?q=London"]];
or this
[someUIApplication openURL:[[NSURL alloc] initWithString: #"http://maps.google.com/maps?q=London"]]
You can even specify the zoom level using the z flag (values between 1-19):
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://maps.google.com/maps?z=8"]];
That should invoke the Google Maps app. I think that these instructions only work on the actual device and NOT in the simulator. Good luck and comment below if you have any problem with the snippets :)
Very simple
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString:#"http://maps.google.com/maps?q=London"]];
Easy as a kiss
#Moshe
Note that on a device that does not have maps installed (not sure if those even exist)
Take an iPhone simulator for example.