Example for startMonitoringSignificantLocationChanges - objective-c

I am new to iPhone programming. I am looking for an example or a demo on how to use startMonitoringSignificantLocationChanges method with the CoreLocation Manager.
I am confused by the documentation because, I am not sure if the same delegate method is called as in the case of invoking startUpdatingLocation. (i.e. the delegate locationManager: (CLLocationManager *)manager didUpdateToLocation: (CLLocation *)newLocation fromLocation: (CLLocation *)oldLocation is called)
Any help on this would be appreciated. Also, I am testing it on the simulator by subclassing of CLLocationManager. This subclass provides a simulation of location services when running on the iPhone Simulator. Is there a better way to test this.

I have done a bit of testing with the significant change API. I posted a sample project on GitHub that lets you play with regular and significant location updates.
This question might also shed some light on what happens when you get woken up for a significant change event.
Update
Another thing you should be aware of, there is a bug in CoreLocation in 4.1. Basically if your app is in the background, then it will crash when core location tries to wake you up. It is fixed in 4.2.

There is a great video session on these new iOS 4.0 CoreLocation and MapKit features from WWDC 2010 that should be freely available in iTunes U for all registered iPhone developers.

Related

Watch Kit: is it possible to vibrate watch programmatically?

Is it possible to vibrate watch while Watch Extension is running? We can do it on iOS in this way (force iPhone to vibrate):
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
I hope there is something similar on WatchKit.
Update: I have added issue to Apple radar and recieved the answer:
Engineering has determined that your bug report (20019274) is a duplicate of another issue (19025053) and will be closed.
19025053 is still open.
Update 2: AudioServicesPlayAlertSound() not working on watch simulator with any sound ID. Seems like function is not supported.
You can now ask the Watch to vibrate if you target watchOS 2.0
To do this all you need to do is call playHaptic on a WKInterfaceDevice instance with any WKHapticType. In the example below it will play the notification haptic.
Swift 3
WKInterfaceDevice.current().play(.notification)
Objective-C
[[WKInterfaceDevice currentDevice] playHaptic:WKHapticTypeNotification];
You can further read the
Apple WKInterfaceDevice Documentation
That's a great question, but unfortunately the answer is no. WatchKit doesn't have any APIs available to control haptic feedback. If you would really like to see this feature supported, I'd suggest you file a radar as a feature request.
This is the answer in objective-c after watchOS 2
[[WKInterfaceDevice currentDevice] playHaptic:WKHapticTypeNotification];
With WatchKit, you have to remember that your code runs on the iPhone and not on the watch. Therefore, AudioServicesPlaySystemSound call from a WatchKit extension would run on the iPhone, not on the watch. It will make the iPhone vibrate.

EAAcessory errors while closing session with iOS 6.0 GM

There is a MFI device that is connected to iPhone 4S (6.0 GM) or to iPad (6.0 GM) via Bluetooth (2.1 + EDR). The project was built on Xcode 4.5 GM. When the app gets EAAccessoryDidDisconnectNotification it will send message [_eaSessionController closeSession];. All these worked nice in iOS 5.1.1 or earler. But on iOS6 with this message I got logs as follows:
-[NSCondition dealloc]: condition (<NSCondition: 0x2e5640> '(null)') deallocated while still in use
Break on _NSLockError() to debug.
Any ideas?
I came across the same issue. This warning is thrown when calling [NSStream close] upon receiving an EAAccessoryDidDisconnectNotification. There should be also some data exchange between the two devices just before the disconnection.
Breaking on _NSLockError will show that at the moment the object is deallocated, some of the threads spawned by the external accessory framework are waiting on conditions. One of those certainly waits on the condition that is being freed, which explains the warning thrown on the console.
I also noticed that the number of threads created by the external accessory framework keeps on growing each time the accessory disconnects then connects, and they seem to be just leaking.
It seems to me that somehow, the external accessory framework does not properly free the resources it allocates, which results in a lot of mess. One of the subsequent effects of this are crashes that happen inside one of those leaked threads during a call to OSAtomicCompareAndSwap64.
I managed to reproduce the issue using a basic sample in which the streams are scheduled on the main thread to avoid any thread management inside the application. I believe it's an accessory management bug on iOS 6 that Apple should be aware of. I'll report it and wait for what they have to say.
Meanwhile, I wonder if anyone of you guys has managed to make any progress on this.
Thanks,
There is no such trouble in iOS 6.1+. To fix this for iOS 6.0 and iOS 6.0.1 please use next solution:
Please note: this is only temp solution allow your users with iOS 6.0 and 6.0.1 continue use your app.
There is a simple hack to avoid application crashes: just create new category and override dealloc method (NSCondition) for iOS 6.0 and iOS 6.0.1:
#import "NSCondition+LeakDealloc.h"
#import <objc/runtime.h>
#implementation NSCondition (LeakDealloc)
- (void) safeDealloc
{
float sVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (sVersion < 6.0 || sVersion >= 6.1)
{
[self safeDealloc];
}
}
+ (void) load
{
method_exchangeImplementations(class_getInstanceMethod(self, #selector(dealloc)), class_getInstanceMethod(self, #selector(safeDealloc)));
}
#end
This solution make new leak, after 20 min tests and about 50 BG/FG swithces instruments shows 10 NSCondition leaks (960 Bytes), BUT no one crash!
The issue has been fixed in iOS 6.1.
There are no more leaking NSCondition or external accessory threads. Apple seem to having fixed the issue properly.

How do I use a RootViewController when making an app without a ViewController?

I am trying to make a simple app from a tutorial that does not have a viewController at all. All the code is in the AppDelegate. I am on xcode 4.2 and I am getting this error:
Applications are expected to have a root view controller at the end of application launch
I'm not sure how to deal with this. There are some blogs out there with fixes but none of them are working for me and I really would like to understand what is going on here. And, how to fix it.
I do have a view that contains some buttons and labels. But I have no "ViewController". The files contained in my project are: AppDelegate.h, AppDelegate.m, and Window.xib only. There is no ViewController.h, ViewController.m
** edit **
I ended up making the app from a 'view based application' instead and just moving all the logic from the app delegate to the view controller. So, I didn't really solve the problem per se. The app works now though. Thanks for the help
It's not possible to have an iOS app that doesn't have a view controller. You can always create a trivial view controller, i.e.,
[[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds].rootViewController =
[[[UIViewController alloc] init] autorelease];
It sounds like you're looking at an old tutorial. UIWindow got a rooViewController property in iOS4. I believe it became required in iOS5 to help keep controller hierarchies and view hierarchies in sync with the addition of custom container controllers (and to fix a corner case where replacing the "root controller" of a UIWindow could stop orientation changes from propagating). There was a WWDC presentation in 2011 that explained this in some detail. I think it was Session 102, Implementing UIViewController Containment.
At then end of the day, there's no good reason not to have a root view controller. Apple wants to be able to assume it's there in their APIs going forward. If the tutorial you're looking at doesn't account for that, it's broken.
While I agree that there may be workarounds, another question to address is: why do you want an app without a view? Even if it's designed to run in the background and present no visual interface, at least make a simple view showing the application name and version, a largeish icon and perhaps a status. This kind of idle screen uses very little system resources, especially when the app is backgrounded, but improves the overall experience of the app.
If you set your deployment target to 4.3 and run on the iPhone 4.3 simulator, you won't get the warning.
To install the iOS 4.3 simulator, go to Xcode > Preferences > Downloads.

Override / cancel iPad application switch gesture

I want to track four finger touches in my application, but they are cancelled as the iPad uses the four finger swipe to switch applications.
Is there a way to cancel / override this gesture?
I looked into this for a game I worked on and I could not find a way to override it. Even if you found a way, it would probably get you rejected from the app store, since there doesn't seem to be any public API for it.
This be my answer. I'm not sure how you'd go about to actually execute the below as I guess implementions do things differently, but generally it sounds as there is a possibility, because after all these are the words of Apple regarding the multitasking gestures:
"Developers are encouraged to evaluate any existing interactions in
their applications for potential sources of interference. In order to
properly interoperate with multitasking gestures, applications must
properly handle the following methods and notifications:
touchesCancelled:withEvent: (UIResponder) cancelTrackingWithEvent:
(UIControl) applicationDidBecomeActive: and
applicationWillResignActive: (application delegate)
UIApplicationDidBecomeActiveNotification and
UIApplicationWillResignActiveNotification notifications These can be
enabled for development via Xcode so you can update your apps to
interoperate with these new gestures. Test them and give us your
feedback in the Apple Developer Forums."
I really don't think you can because I have watched countless videos on how to override on iPhone/iPod but there are no ones for iPad must be so you can't cheat on games!

Why are MKPolyline and MKPolygon working in iOS 3.2.2 (on an iPad)?

As far as I can tell, technically MKPolyline and MKPolygon should not be functional/available when running on an iPad or any other device prior to iOS4. Nevertheless, when I installed 3.2.2, on the device, and updated my build tools with the latest (non-beta) iOS 4.2 SDK, they both work just fine, along with their associated views. What the hell?
I'm not exactly complaining here, given that the alternative would be NVPolyline and it doesn't play well with a huge number of points. I'm just confused. Can someone explain why these classes are available and working on the iPad?
I have not, however, had any success subclassing MKOverlayPathView on 3.2.2, even though MKPolylineView and MKPolygonView both descend from it.
The docs certainly claim that it was first available in 4.0, but I remember the new MapKit overhaul being part of the diff for 3.2. I think the docs just have the timeline of that update wrong.