iOS 6 and Location Services not working - core-location

I've updated my iOS SDK to version 6. After that I've compiled my app (works fine in iOS 4 & iOS 5) but now the location services doesn't work. My delegate isn't receiving any update and the upper location arrow is not appearing... I'm starting the service as the usual way:
[locationManager startUpdatingLocation];
My project is non ARC.
What is happening? This is driving me crazy...
Thanks in advance.

Make sure you have a CFBundleDisplayName in your project's .plist file. Adding that key fixed it for me.

Just set the property pausesLocationUpdatesAutomatically of Location Manager to NO. This is a new feature of IOS 6 that disable Location Updates when application runs in background. The default value of this property is YES.

This is a change in iOS6:
You need to implement locationManager:didUpdateLocations: instead of locationManager:didUpdateToLocation:fromLocation to be notified when the location is updated.
You should also read the documentation about startUpdatingLocation.

In my case, I had the location manager under a different class and I was calling this class from the main controller. This was not working and the didUpdateLocations was not called.
//
// LocationServices.h
//
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#interface LocationServices : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
#property (nonatomic, retain) CLLocationManager *locationManager;
- (void)startLocationServices;
#end
// LocationServices.m
#import "LocationServices.h"
#implementation LocationServices
#synthesize locationManager, currentLocation;
- (void)startLocationServices {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.pausesLocationUpdatesAutomatically = NO;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
if ([CLLocationManager locationServicesEnabled]) {
[locationManager startUpdatingLocation];
} else {
NSLog(#"Location services is not enabled");
}
}
////////////////////////////////////////////////
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
CLLocation* location = [locations lastObject];
NSLog(#"Updated: latitude %+.6f, longitude %+.6f\n",
location.coordinate.latitude,
location.coordinate.longitude);
}
#end
// Main controller
- (void)viewDidLoad {
[super viewDidLoad];
.....
LocationServices *locationSerices = [[LocationServices alloc]init];
[locationSerices startLocationServices];
......
}
The above code does not work. Why? I do not know ....you can easily lose interest when you spend so much time trying to do a thing that is supposed to be simple. iOS is very complicated and unfriendly programming environment. There are many ways to do one thing, only one works, you cannot mix and match without introducing a problem. You have to do everything by the book or you or you get nothing. Not even a hint that you did something wrong ... frustrating ...
Instead when I implemented
locationManager:(CLLocationManager *)manager didUpdateLocations:
in the main controller everything worked fine

The issue seems to be resolved in IOS 6.1 Beta2 - http://www.youtube.com/watch?v=aFZR0eMUV74

setting CFBundleDisplayName solved the problem for me. Same thing location update was never called, just set the info.plist parameter and it start working.

I've tried everything in plist files, cleans, rebuilds, new targets, configurations, etc, etc, etc. Nothing worked. But FINALLY I've fixed it. I had to create a new Xcode 4.5 project from scratch, reconfigure it, add file by file and framework by framework manually. It seems that my old XCode project had something internally incompatible with last XCode. I write this here because maybe it can save someone's next 10 hours of work.

Am I being too simplistic here? Under Privacy, Locations looks the same as it did in previous issues.What's all the fuss about?

Related

The goback function of WKWebView does not execute javascript code

In UIWebView, if i call the function goback, the previous page will be present and execute its js code and set title on navigation bar. However, this do not work in wkwebview, it seems that wkwebview cache something and the js code is not executed.
I think the WKWebView is actually the more correct behaviour regarding the load event.
I have found that the pageshow event is better suited for code that needs to run on navigation changes.
Something like this should work in the WKWebView:
window.addEventListener('pageshow', function(event) {
// We were just shown again. Either initial load or due to
// navigation.
});
I was having a similar problem and the webpage was't being reloaded (on iOS 9.2 or higher versions) because it was showing a cached one, when calling goBack.
'Fixed' that clearing the cache data before calling goBack on the WKWebView. I still don't know if it is an iOS bug or Apple just decided to change the default behaviour from iOS 9.2.
In Objective-C would be something like this:
- (void)goBack {
[self cleanCacheWithCompletionHandler:^{
[super goBack];
}];
}
- (void)cleanCacheWithCompletionHandler:(void (^)(void))completionHandler {
if ([WKWebsiteDataStore class]) {
NSSet *websiteDataTypes = [NSSet setWithArray:#[ WKWebsiteDataTypeDiskCache,
WKWebsiteDataTypeMemoryCache]];
NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:completionHandler];
} else {
completionHandler();
}
}
Note that I subclassed WKWebView in the sample code and that you have to check the availability of WKWebsiteDataStore as it is new to iOS 9.

Issue loading a url in WKWebView using Xcode 7 beta3

I am doing a quick test on WKWebView to evaluate its benefits and drawbacks. But i have found is that i am able to load urls using Xcode 6.4 and iOS 8 but having issues loading the same URL in Xcode 7 beta 3.
This is what i am doing :
- (void)viewDidLoad {
[super viewDidLoad];
// First create a WKWebViewConfiguration object so we can add a controller
// pointing back to this ViewController.
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc]
init];
WKUserContentController *controller = [[WKUserContentController alloc]
init];
// Add a script handler for the "observe" call. This is added to every frame
// in the document (window.webkit.messageHandlers.NAME).
[controller addScriptMessageHandler:self name:#"observe"];
configuration.userContentController = controller;
// This is the URL to be loaded into the WKWebView.
NSURL *jsbin = [NSURL URLWithString:k_JSBIN_URL3];
// Initialize the WKWebView with the current frame and the configuration
// setup above
_webView = [[WKWebView alloc] initWithFrame:self.view.frame
configuration:configuration];
// Load the jsbin URL into the WKWebView and then add it as a sub-view.
[_webView loadRequest:[NSURLRequest requestWithURL:jsbin]];
[self.view addSubview:_webView];
}
Is there something wrong i am doing or its just the beta version of Xcode and iOS 9?
Thanks,
It's broken in xcode 7 (Beta)/Swift 2.0 as far as I can see.
I'm using Beta 5 but had the same problem with some earlier Betas.
Fingers crossed it will be fixed in the next beta. I'm sure it will be in the final release.
Maybe they've intentionally blocked it's use due to some issues with Swift 2.0 that they haven't fixed yet.
In Xcode 7 and iOS 9 you're going to run into problems when using a URL without a SSL certificate.
Adding a certificate will "solve" this issue.
You could also implement the new SFSafariViewController.
Using a domain with without SSL will result in a blank page at least in iOS 9.0.1.

UIPageViewController memory leak

It seems that UIPageViewController is holding the initial content view controller forever.
For example:
DataViewController *startingViewController = [self.modelController viewControllerAtIndex:0 storyboard:self.storyboard];
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];
self.pageViewController.dataSource = self.modelController;
The startingViewController is never released until the pageViewController itself it released.
To reproduce this bug, just create a new project in XCode using the Page-Based Application template. And add 3 lines of code into DataViewController.m
#property NSInteger debugIndex; // file scope
NSLog(#"DataViewController[%d] created", self.debugIndex); // in viewDidLoad
NSLog(#"DataViewController[%d] dealloc", self.debugIndex); // in dealloc
And when you scroll the demo App in vertical orientation, you'll get logs like this:
DataViewController[0] created
DataViewController[1] created
DataViewController[2] created
DataViewController[1] dealloc
DataViewController[3] created
DataViewController[2] dealloc
DataViewController[4] created
DataViewController[3] dealloc
DataViewController[5] created
DataViewController[4] dealloc
DataViewController[6] created
DataViewController[5] dealloc
DataViewController[0] is never deallocated.
Any ideas about this?
Thanks!
Are you using transitionStyle UIPageViewControllerTransitionStyleScroll? I encountered the same or a similar problem which seemed to disappear when using page curl animations instead.
The problem was compounded for me because I was allowing a UISliderBar to set the position in the content. So on change of the UISliderBar, I was calling setViewControllers:direction:animated:completion: which caused more and more view controller references to get "stuck" in my UIPageViewController.
I am also using ARC. I have not found an acceptable way to force the UIPageViewController to let go of the extra view controller references. I will probably either end up using the page curl transition or implementing my own UIPageViewController equivalent using a UIScrollView with paging enabled so I can manage my own view controller cache instead of relying on UIPageViewController's broken view controller management.
I'm not sure you still got the problem, but I had the same problem and I found the solution.
I don't know the reason, but it works.
I'm setting the first viewController right after addSubview, rather than before addChlidViewController.
-(void)settingPageViewController{
if (!self.pageViewController) {
self.pageViewController = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.delegate = self;
self.pageViewController.dataSource = self;
[self addChildViewController:self.pageViewController];
[self.pageViewController didMoveToParentViewController:self];
[self.containerView addSubview:self.pageViewController.view];
[self.pageViewController setViewControllers:#[[self viewcontrollerAtIndex:0]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
}
and the first viewController will dealloc in the right time.
also, I found if call
[self.pageViewController setViewControllers:#[[self viewcontrollerAtIndex:0]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:^(BOOL finished){
NSLog(#"finished : %d",finished);
}];
before addSubView and the completion block will not call.
and I reckon this block is the reason why the first viewController didn't dealloc.
I'll go find out why it didn't callback, and improve the answer~
cheers
After a few attempts to figure out what was happening on a similar issue, I noticed that in my project there were 2 reasons that caused a retain problem and resulted in having a UIPageViewController being forever retained.
1) there was a circular reference between the UIPageViewController and the UIViewcontroller that was presented (this was fixed by changing the properties to weak from strong in both classes)
2) and the main fix consisted in changing
[self setViewControllers:#[initialDetailsViewController] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
to
__weak __typeof__(self) weakSelf = self;
[weakSelf setViewControllers:#[initialDetailsViewController] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
I hope this helps someone
same problem here
i resolved it by keeping my initial viewController in the variable
and instead of creating the same vc on particular pageIndex i just reuse it
I had same problem and solved the following:
[startingViewController release]; where the end point of initialization.
then the first ViewController will be deallocated.

do runloops/multi-threading/timers behave differently on iOS6?

I just installed Xcode 4.5 to start testing some code on iOS6 devices.. I wanted my existing code to be runnable on both iOS 5 and iOS 6 obviously. The same code (below) that used to work on Xcode 4.3 stopped working on Xcode 4.5:
-(BOOL)readFromRingBuffer
{
NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:0];
ringBufferReaderTimer = [[NSTimer alloc] initWithFireDate:fireDate
interval:0.25
target:self
selector:#selector(readRingBufferDataBit)
userInfo:NULL
repeats:YES];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:ringBufferReaderTimer forMode:NSDefaultRunLoopMode];
}
I had to put this line for the method to fire:[ringBufferReaderTimer fire]; (didn't have to do this on XCode 4.3)
but then it would go through the method once and nothing would happen.. in general.. I see weird things happening.. is there something I need to know about threading in iOS6 that I'm not aware of? A quick googling doesn't tell me much..

Attempting to create USE_BLOCK_IN_FRAME ... EXC_BAD_ACCESS with NSFetchedResultsController

This is an update to my problem. I am receiving this warning now when the program aborts.
warning: Attempting to create USE_BLOCK_IN_FRAME variable with block that isn't in the frame.
I can't find much information on what this means.
This has me baffled. I get the EXC_BAD_ACCESS error. I have NSZombieEneabled (which helped with an earlier problem), but there is no call stack to trace.
I have some nearly identical code that is working with respect to another fetched result controller.
This seems to have something to do with the relationships between the job entity and its associated client entity. The relationship is [job entity] <<--> [client entity].
Initially, I see that the code works without error where the job entity corresponding to the selected row has no client entity linked through a relationship. So in the case where it fails, this points to a client entity, but when it doesn't fail, the pointer is nil.
When I encounter this problem, I start the application and go directly to the job picker view and select a cell. It's at that point that the problem occurs.
I did an experiment by starting the application and going to the client picker view first, knowing that a fetch would occur of all of the client entities. Then I went to the job picker view and selected a cell. The problem did not occur.
Since I am just trying to pass a pointer to a job entity that was already fetched, I don't understand what's happening.
By the way, the code was working fine before I switched to using NSFetchedResultsControllers. I like what they can do for me, but there are some dynamics going on here that I haven't figured out.
The logging is not showing me anything I understand toward resolving the problem.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
userState.selectedJob = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSLog(#"\n\n(1 Pick) indexPath: %#\n",indexPath);
NSLog(#"\n\n(1 Pick) userState: %#\n",userState);
NSLog(#"\n\nnumber of Objects in job fetchresultscontroller = %d", [[fetchedResultsController fetchedObjects] count] );
NSLog(#"\n\n(1 Pick) selected job: %#\n",[self.fetchedResultsController objectAtIndexPath:indexPath]); // This line is causing the problem...
NSLog(#"\n\n(1 Pick) selected job: %#\n",userState.selectedJob); // Omitting the line above, this line fails
[self.navigationController pushViewController:userState.jobInfoTVC animated:YES];
}
The debug output is
2011-05-07 09:27:04.142 job1[6069:207]
(1 Pick) indexPath: <NSIndexPath 0x5952590> 2 indexes [0, 3]
2011-05-07 09:27:04.142 job1[6069:207]
(1 Pick) userState: <UserStateObject: 0x5919970>
2011-05-07 09:27:04.143 job1[6069:207]
number of Objects in job fetchresultscontroller = 4
(gdb)
The final code should be as simple as this, which led me to all of the logging:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
userState.selectedJob = [self.fetchedResultsController objectAtIndexPath:indexPath]; // Original failure was at this line
[self.navigationController pushViewController:userState.jobInfoTVC animated:YES];
}
I use the singleton userState to keep track of what the user has done. So I keep last selectedJob and selectedClient entity pointers there. This has worked okay before I switched to NSFetchedResultsController.
I have also had a problem with Attempting to create USE_BLOCK_IN_FRAME variable with block that isn't in the frame. Although mine wasn't anything to do with NSFetchedResultsControllers.
Possibly Your Problem
I noticed you mention you are using a singleton, so maybe your problem is solved at this link:
http://npenkov.com/2011/08/01/solving-issues-like-warning-attempting-to-create-use_block_in_frame-variable-with-block-that-isnt-in-the-frame/
From the link:
Exactly in session manager I used the macro, before #synthesize – this was the problem, static definitions should not appear before synthesized methods. So if you have something like:
SYNTHESIZE_SINGLETON_FOR_CLASS(SessionManager)
#synthesize loggedUserId, ...
Just replace it with:
#synthesize loggedUserId, ...
SYNTHESIZE_SINGLETON_FOR_CLASS(SessionManager)
enter code here
My problem
The problem I had was to do with duplicating a variable declaration, in this case the variable inherited from NSManagedObject :
- (void)functionThatDoesSomething {
VariableInheritedFromNSMObj *variableA = nil;
for (VariableInheritedFromNSMObj *variableA in [self containerObject]) {
NSLog(#"a = %#\n", [variableA name]);
}
[variableA setName:#"StackOverflow"];
}
Moving the first line, where variableA is initialised to nil, to after the loop fixed the problem. In my production code I then changed the name of one of the variables.
Hope that helps you or someone else who comes across this problem. This error seems to manifest itself in many different ways.
Is the deployment target OS version set to a lower one than you have debugging support for in Xcode 4.2? When this happened to me, the deployment target had somehow changed to 4.1, but I only had the 4.3 simulator without the additional debugging support for 4.0-4.1.
There are ways to fix this:
Install the debug symbols for your lower OS version from the Xcode preferences. Go to downloads, components and install OS 4.0 - 4.1 Device Debugging Support (or earlier if you need it).
Set the deployment target to 4.3 or higher.
If you choose the former, it's probably worth ticking the box in preferences to download the updates automatically.

Resources