I am experimenting with apple mapkit apple mapkit guide, and i noticed that to show the user location (blue dot), it suffice to set show userlocation to true in storyboard. I am testing on simulator (trying iphone 6 and 7) and i emulate locations using gpx files.
My problem is no blue dot appears on screen. What can be wrong ?
Are you actually starting up the location manager and updating the location?
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
And don't forget to ask the user for permission as well.
Related
I am experiencing an issue when using the iPad Camera in iOS 8. I've seen some older questions and a thread on the Apple Developer Forums from during the beta but still haven't find a solution.
There seems to be two parts to this issue.
1) The camera itself rotates when the device orientation rotates, eg the world is on its side
2) When opening the camera in Landscape, the overlay does not appear. When opened in Portrait it is fine.
It is an app using iOS7 as the Base SDK, problem only occurs when running the app on a device that has been upgraded to iOS8. The app is not using storyboards, it is using nibs.
I'm hoping to push out a fix for this with Xcode 5.1.1 before moving onto the iOS8 specific fixes and using it as a Base SDK in the next version.
Here is my code to bring up the camera:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == YES) {
// Create Camera
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.showsCameraControls = NO;
// Set up custom controls view
[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
self.overlayView.frame = imagePicker.cameraOverlayView.frame;
imagePicker.cameraOverlayView = self.overlayView;
self.overlayView = nil;
// Show Camera
[self presentViewController:imagePicker animated:NO completion:nil];
[imagePicker release];
}
I have also tried
And the Layout of the Toolbar (sitting at the bottom) of the OverlayView:
If I change that to sit "at the top" it appears in both portrait and landscape! So it must have to do with the view/window/something size, though it's strange how its behaviour would change when the layout has stayed the same.
I have tried it with both showsCameraControls = YES and hashing out the OverlayView block, and problem #1 persists so it's not to do with the overlay at app.
I'm hoping someone has found an answer to this, it seems like quite a common problem.
Please let me know if you need any further details.
Edit 1: Fixed the Overlay (Issue #2)
It wasn't applying the orientation to the OverlayView, fixed it like this:
// Grab the window frame and adjust it for orientation - from http://stackoverflow.com/a/15707997/520902
UIView *rootView = [[[UIApplication sharedApplication] keyWindow]
rootViewController].view;
CGRect originalFrame = [[UIScreen mainScreen] bounds];
CGRect screenFrame = [rootView convertRect:originalFrame fromView:nil];
...
self.overlayView.frame = imagePicker.cameraOverlayView.frame;
I suspect that it's related to the camera not realising it's orientated too, will keep searching for a fix for Problem #1.
Edit 2: Update on Issue #1
Looks like the camera rotating might be an Apple issue. On iOS8 if you open up the Contacts app, edit a contact and choose 'Take Photo', the exact same issue occurs - in a default Apple app!
I still can't find a fix so I am just destroying and recreating the imagePicker on each orientation change for now, it's ugly but will suffice until Apple release a fix or a better solution pops up.
Apple fixed this problem in iOS 8.1.
when i display interstitial ads with
[interstitial presentFromViewController:self];
i get the warning that this method is deprecated in iOS 7. But it still works fine!
When i display the ad view with
[self requestInterstitialAdPresentation];
[interstitial presentInView:self.view];
i get no warning and the ad is loading but there is no (X) in the ad that the user can close the ad.
Do somebody knows how to fix this?
hey there this is the troublemaker
[interstitial presentInView:self.view];
instead try this (delegate methods) t'should be removed manualy
-(void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd{
if (interstitial != nil){
_adPlaceholderView = [[UIView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:_adPlaceholderView];
[interstitial presentInView:_adPlaceholderView];
}
and on did unload
- (void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd
{
NSLog(#"ad has been unloaded");
[_adPlaceholderView removeFromSuperview];
_adPlaceholderView = nil;
}
I have the same bug Use the old API or put custom x button .I thinks this is a bug from presentinView . i am not sure it could be apple desired feature there's no documentation on this.At least i haven't seen any.Please share if you find something official on this.
I am using Xcode 4.1, on iOS Simulator 4.3
I have imported the ZXing library into my project as per the instructions in their README.
When I try to load the controller all I see is a white screen with a Cancel button at the bottom. I know the simulator can't take photos but the controller is then supposed to let you choose an image to decode from the photo library. Has anyone had this issue or has any ideas on what is causing it?
ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO];
QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];
NSSet *readers = [[NSSet alloc ] initWithObjects:qrcodeReader,nil];
[qrcodeReader release];
widController.readers = readers;
[readers release];
[self presentModalViewController:widController animated:YES];
[widController release];
EDIT: Forgot to mention, there are pictures on the simulator that I loaded already.
but the controller is then supposed to let you choose an image to
decode from the photo library
Where did you see this? It's not in the README or the code.
The widget doesn't provide an image picker backup. The old Barcodes app (found in cpp/iphone/legacy/Barcodes_original) did but the current Barcodes app doesn't. If you need this, you'll have to implement it yourself. The old Barcodes app might be useful as guide, to some extent.
I'm using MPMoviePlayerViewController - with the player controls set to: MPMovieControlStyleFullscreen
I'm having a problem with some of buttons that are in MPMovieControlStyleFullscreen: forward, reverse, and fullscreen (the one with the arrows pointing at eachother).
I would like to either remove the forward, reverse, and fullscreen buttons or control what they do when the user taps them.
Thank you!
There isn't a way to customize the MPMovieControlStyle values provided by Apple. What you need to do is is turn off the Apple controls (MPMovieControlStyleNone) and then create your own custom controls. Apple is fine with you putting your own UIViews in to the hierarchy here, so you can get started with something like this:
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: YOUR_URL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
UIView *movieView = moviePlayer.view;
[movieView addSubview: _movieControlsView];
[movieView bringSubviewToFront: _movieControlsView];
Where _movieControlsView was set up earlier in code or in IB.
Aesthetically, you can do what you want, but I would recommend sticking with something that looks like Apple's choices so as not to confuse the user. For the project I just finished, I created a transparent button the exact size of the movie player. Clicking the button fades in a control bar on the bottom with my custom controls. If one of the controls isn't clicked, the control bar fades back out again after a few seconds.
First off, MPMoviePlayerController is a little different than MPMoviePlayer*View*Controller, so some of these answers lead to problems when converting applications that were built in an iOS 4.3+ environment.
I've built some apps using MPMoviePlayerController that worked fine when built in iOS 3.2. When I rebuilt it with XCode 3.2.6, (iOS 4.3), the videos don't even play on the iPhone. I since fixed that by adding the MPMoviePlayerController instance to a subView, then presenting a modal (Player is a UIViewController) with the movplayer in fullScreenMode:
//from didSelectRowAtIndexPath
Vid *selected = [items objectAtIndex:position];
player = [[Player alloc] init];
movplayer = [[MPMoviePlayerController alloc] initWithContentURL:selected.vidURL];
movplayer.view.frame = player.view.bounds;
movplayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[player.view addSubview:movplayer.view];
[self presentModalViewController:player animated:YES];
[movplayer setFullscreen:YES animated:NO];
[movplayer play];
[player release];
//movplayer is released inside - (void)exitedFullscreen:(NSNotification*)notification
This was done on account of the UINavigationBar being half cut off when rotating.
When I got to the iPad version of the app the modal option wouldn't work aesthetically. It was also having the UISplitViewController navBar and toolbars half cut off when rotating in full screen mode. So I tried implementing MPMoviePlayerViewController instead of MPMoviePlayerController. With this conversion, XCode gave me errors when trying to set:
movplayer.controlStyle = MPMovieControlStyleEmbedded;
The proper way to do this with a MPMoviePlayerViewController is:
movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
When the player is added as a subView, the pinch gestures will toggle the player between fullScreen and the size of your parentView (player.view.bounds) smoothly, as well as preserve the toolbars and navBars native to the parent.
//iPad version with a view (viewForMovie) inside the DetailViewController
movplayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[current vidURL]];
movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
movplayer.view.backgroundColor = [UIColor clearColor];
movplayer.view.frame = viewForMovie.bounds;
[viewForMovie addSubview:movplayer.view];
So these two examples show some workarounds for those who want to convert their iPhone or iPad apps to a newer iOS version.
Try setting MPMovieControlStyle of your MPMoviePlayerController object to MPMovieControlStyleNone
I have a problem what I suppose is rather trivial...
I have coded an app using the mapkit and have done the development on my Mac using the simulator which has no GPS. Therefore did I hard code the coordinates to simulate a user position. Today as I tried my app on my iPhone for the first time I thought I only had to change my code a bit in order to read the coordinates from the GPS and to get the information about the users position. But it did not work that easy. Does anyone have an idea how to solve this? I need the user longitude and latitude to calculate the distance to another position and I thought I could do something like this...?
CLLocationManager *clm = [[CLLocationManager alloc]init];
[clm.delegate self];
[clm startUpdatingLocation];
userLocationFromGPS = clm.location.coordinate;//the userLocationFromGPS is a CLLocationCoordinate2D userLocationFromGPS object
user = [[Annotations alloc]initWithCoordinate:userLocationFromGPS];
[user setTheTitle:#"You are here!"];
userLocationPlain = [[CLLocation alloc]initWithLatitude:userLocationFromGPS.latitude longitude:userLocationFromGPS.longitude];
I need the coordinates but cant figure out how to get them...any ideas?
Thanks in advance!
CLLocationManager reports location asynchronisly, so you would need to provide a delegate.
Consider going over LocateMe code sample. Also, you should hard-code coordinates in the simulator. The simulator would use the Apple headquarters coordinates.
Here is some refactoring for the code you provided (I didn't run it):
Consider doing the following:
CLLocationManager *clm = [[CLLocationManager alloc] init];
clm.delegate = self;
[clm startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
Annotations *user = [[Annotations alloc] initWithCoordinate:newLocation];
[user setTheTitle:#"You are here!"];
CLLocation *userLocationPlain =
[[CLLocation alloc] initWithLatitude:newLocation.latitude
longitude:newLocation.longitude];
// At some point you should call [manager stopUpdatingLocation]
// and release it
}
As this says, you might need to first import the location framework.
Thank you both for answering!
msaeed:
Your code is looking good. I have defined a delegate but forgot to implement the method as you do in you example. I will try it out! Thanks!
mcandre:
Yes I added the framework and I use the functionalities in it in other methods in my app, when reading and handling position from a KML.
/MACloop