Using CoreLocation with Apple Watchkit - ios

The apple iOS/Watch simulator works great with the default Core Location implementation.
However, does this really work with the device later on? Or do I need to build my implementation around a openParentApplication-pattern?
Thanks,

Since your watch extension runs on the phone, it has access to the same features as a normal iOS app and can use CoreLocation. However, it uses the CoreLocation permissions that were granted to your main app, so make sure your main app uses CoreLocation too so that the user will be asked to give your app permission to access those services.

WatchKit extensions have access to the same technologies found in iOS apps but because they are extensions, the use of some technologies may be restricted and the use of others is not recommended.
Apple recommends to avoid using technologies that request user permission, like Core Location.
Using the technology from your WatchKit extension could involve
displaying an unexpected prompt on the user’s iPhone the first time
you make the request. Worse, it could happen at a time when the iPhone
is in the user’s pocket and not visible.
The best solution for performing any long-running tasks is to let your
iOS app perform the task instead. For example, instead of starting
location services in your WatchKit extension, start it in your iOS
app. Your iOS app can gather the needed data and put it in a shared
app group so that your extension can access it later.

Related

Xamarin ios requesting unnecessary permissions

I have an Xamarin App for ios and android. Lately Apple has been rejecting my builds due to missing purpose strings, for features my app does not use.
My app only needs access to Camera and Media Storage. I request permission once that feature is being used. However Apple is requiring I explain why my app needs access to:
contacts
location
bluetooth
siri
microphone
None of which are in use! It seems like every time I do a release something is added to the list. My info.plist is getting filled with messages like "This app does not require this feature". Its very unprofessional.
It seems that if I use a nuget package that has the potential to use a feature, the app thinks that feature IS in use.
Is there a way to make it very clear my app does NOT use these features and to NOT ask the user for permission to use them when they first run the app? (This is not a programmed permission request that is occurring.)

Share AsyncStorage from iOS react native app with Apple Watch

I'm developing the main app with react native and the Apple Watch with Swift.
The main app (react native) uses AsyncStorage to store some values, that then are used as params for a fetch that shows a list.
After running the simulator, I found manifest.json inside
~/Library/Developer/CoreSimulator/Devices/D10E869B-040B-446F-9B8B-754F111442EC/data/Containers/Data/Application/AC837AFE-312B-4861-906D-EC9EEE7D029B/Document
s/RCTAsyncLocalStorage_V1
with the data inside.
I need to access those values in the Apple Watch in Xcode to do the same job as the iOS app. How do I access that data?
Since Apple Watch apps run independently from iOS app since watchOS 2, there’s really no way to directly access the data stored locally on iPhone — you’ll need to maintain some form of communication between your iOS and watchOS apps.
The framework intended for this is called WatchConnectivity. I see two more-or-less suitable solutions for your case:
Using transferFile to transfer your file from an iOS device to an Apple Watch whenever it got updated. The viability of this option highly depends on how big your file is.
Or you can just use updateApplicationContext to pass an already serialized data instead of transferring a raw JSON file — again, highly depends on your specific needs.
Unfortunately, I don’t know how WatchConnectivity is supposed to work with ReactNative. If you want a deeper introduction to this framework — I highly recommend watching this amazing video from WWDC 2015.

Access App Info From Watch

Im a bit new to IOS and Swift. I generally use Cordova and let the "magic" behind the curtains unfold when building IOS apps. It seems, however, that developing for Apple Watch using watch kit isn't so "magical".
What I am trying to do is access authentication information via my watch, that was entered into my IOS app; then utilize that info to make API requests which I will parse and present in the apple watch. I don't want users to authenticate using the watch, hence there is some handshaking that needs to be done. Please help, not sure where to get started...
So, I used MMWormholeSession with Cordova in conjuction with WCSession. I had to do some modifications to the MMWormhole code, but all the puzzle pieces were in there.

How to get the current location in a WatchKit app?

If I'm not wrong, the App Watch can't take locations itself and needs to request it to the iPhone, so the current location is got in the WatchKit extension at iOS side... right?
I think this is a quite common thing WatchKit developers would do, but I don't find a clear tutorial/example of it, could somebody tell me one or post me some code? In addition, do you know if the way to deal with locations changes in watchOS 2?
EDIT: I've found that in some posts it is said that CoreLocation can be accessed from the WatchKit extension, and in others I've read that only the iOS app can... which is the correct?
You can access CoreLocation and all its methods directly from WatchKit itself. There's no need to employ any sort of additional logic, such as opening the parent app.
In watchOS 1, your WatchKit app is technically running on the iPhone, and you can therefore use (almost) any frameworks available to you on the iPhone (such as CoreLocation).
In watchOS 2, the WatchKit app is running on the Watch itself. I have done some research and I've not found anything that indicates you will have to make any changes to your usage of CoreLocation, and I will therefore assume the frameworks automatically handle the communication between the iPhone and the Watch.
I'll update this answer if I find anything indicating that you will have to employ some other logic to make this work in watchOS 2.

Using Core Location in Apple WatchKit

I'm currently developing an apple watch extension. Anybody knows if the current location is provided by iPhone or Watch itself?
I can't find any information about this and i need to draw a compass pointing where the watch is pointing.
In order to do what you want you don't need CoreLocation you just need a magnetometer.
AFAIK the Apple Watch doesn't have one built in.
The sensors it has are...
Accelerometer
Gyroscope
Heart rate sensor
Barometer
No magnetometer though.
According to Apple's Dev Documentation:
The best solution for performing any long-running tasks is to let your iOS app perform the task instead. For example, instead of starting location services in your WatchKit extension, start it in your iOS app. Your iOS app can gather the needed data and put it in a shared app group so that your extension can access it later. Use the openParentApplication:reply: method to initiate tasks and receive a reply or use a shared group container to communicate details between your iOS app and WatchKit extension. For information about how to handle communication between your iOS app and WatchKit extension, see Communicating Directly with Your Containing iOS App.
P.S. I am working on similar app.
You can't use CoreLocation from the watchkit extension. You can however use an api to open the parent app (in the background) and ask your parent api for the information. The api is really nice because you can use it with a reply so that you can easily get the information back:
+ (BOOL)openParentApplication:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo, NSError *error)) reply; // launches containing iOS application on the phone

Resources