WatchKit / Healthkit - Unable to create a swimming HKWorkout Session - watchkit

I'm setting configuration for a HKWorkout session as follows:
self.configuration = [[HKWorkoutConfiguration alloc] init];
self.configuration.activityType = HKWorkoutActivityTypeSwimming;
self.configuration.locationType = HKWorkoutSessionLocationTypeOutdoor;
self.configuration.swimmingLocationType = HKWorkoutSwimmingLocationTypeOpenWater;
HKWorkoutSession *session = [[HKWorkoutSession alloc] initWithConfiguration:self.configuration error:&error];
if (error)
{
NSLog(#"Error with Healthkit Session: %#", error);
}
if (session == nil)
{
NSLog(#"*** Unable to create the workout session: %# ***", error.localizedDescription);
abort();
}
I'm using Xcode 8 but for that matter it also appears in the simulators for Xcode 8 beta 3 too. Using Apple Series 2 Watch Simulator of course.
And I get the following error. Is there something that I am doing horribly wrong here or is there another way to test swimming workout sessions?
* Unable to create the workout session: Swimming sessions are not supported on this device *

Swimming workouts cannot be tested on the Apple Watch simulator. You must use Series 2 hardware to test.

At the risk of stating the obvious, can you test it on an actual watch?
I've never tried doing exactly what you are doing here, but there are lots of other functions that aren't supported on the emulators - and looking at the error message that appears to be the case here.
Sorry I can't be more help

Related

flutter audio play delay

I am using the audioplayers package to play my mp3 audio files that are stored in firebase cloud storage. There is a significant delay for both Android and iOS and only just slightly faster in Android. I have since moved all my audio sound files to local asset.
AudioPlayer audioPlayer = AudioPlayer(mode: PlayerMode.LOW_LATENCY);
play(String url) async {
int result = await audioPlayer.play(url);
if (result == 1) {
// success
print('success');
}
}
Just a few days ago, I tested with the audio player in iOS Swift and play some audio files from firebase cloud storage but I did't encounter any significant delay due to buffering and it was a lot faster.
I need to find a way to get around this as I have many audio files and they need to be stored in the network. Anyone of you have encountered similar issues and do you have any good suggestions?
Update
Made this second PR that addresses few shortcomings of the first original PR. Both are merged into master branch of audioplayers.
My PR changes are:
playbackRate is always used in playImmediatelyAtRate instead of constant values -- initially set by the library to _defaultPlaybackRate i.e. 1.0
playImmediatelyAtRate is added to resume method as well, not just play
Original Solution
This is the final code that helped solving the audio play delay for the OP:
in play & resume method
AVPlayer *player = playerInfo[#"player"];
float playbackRate = [playerInfo[#"rate"] floatValue];
if (#available(iOS 10.0, *)) {
[player playImmediatelyAtRate:playbackRate];
} else {
[player play];
}
So calling [player playImmediatelyAtRate:playImmediatelyAtRate:playbackRate] instead of [player play]; seems to fix the issue.
So far it hasn't been merged into the pub and is still an open the first incomplete PR has been merged, second PR as well.
Original comment:
There's this open pull request that should fix delay on iOS. that hasn't reached release version. Also there's this discussion on big initial lag.

watchOS AudioRecorder has no input, doesn't ask for permission

I am using this code to show the AudioRecorder on the Apple Watch (taken from https://www.raywenderlich.com/345-audio-recording-in-watchos-tutorial)
let outputURL = chatMasterController.newOutputURL()
let preset = WKAudioRecorderPreset.narrowBandSpeech
let options: [String : Any] =
[WKAudioRecorderControllerOptionsMaximumDurationKey: 30]
presentAudioRecorderController(
withOutputURL: outputURL,
preset: preset,
options: options) {
[weak self] (didSave: Bool, error: Error?) in
guard didSave else { return }
print("finished audio to \(chatID) at \(outputURL)")
print(outputURL)
}
The Recorder pops up however it doesn't seem to take any input. The wave forms don't rise while speaking and trying to play the recording afterwards leaves me with 0.2seconds of silence no matter how long the recording is.
I've tried another app that's making use of the microphone and this app did ask me for permission to record audio. I have feared having dismissed the permission before so I have reinstalled my app which however didn't change anything - no permission being asked, no input being generated.
Is there something I've missed e.g. importing a lib?
I've now figured it out. You don't just need the Privacy - Microphone Usage Description string in your Watch app's plist - you also need to set it in the iPhone's plist.
Only setting it on the Watch does nothing, only setting it on the iPhone doesn't let you allow it on the Watch directly. So you need it on both.
No idea why this isn't documented anywhere but it fits Apple's "we are going downhill" movement :)

Altbeacon library not working on Android 5.0

Yesterday I got the update for Android 5.0 on my Nexus 4, and the altbeacon library stopped detecting beacons. It appears that didEnterRegion and didRangeBeaconsInRegion are not even getting called when monitoring and ranging, respectively.
Even the Locate app from Radius Networks behaves differently now, the values from beacons, once they are detected, doesn't get updated anymore and often it appears as if the beacons went out of range.
One thing I noted differently, is that now in the logcat it appears the following line "BluetoothLeScanner﹕ could not find callback wrapper". I went ahead and looked for that class and saw that it was introduced with Android L, but I don't know if that has something to do with it.
It's important to say that before the update I had been working with both the Locate app and the Reference Application without any trouble.
I don't know if this is a generalized problem or not, but if it happened to me I'm sure it could happen to someone else, so any help it would really be appreciated.
Thanks in advance!
UPDATE:
After failing at getting the library to work I decided to try the Android L branch of the library. What I did was that I plugged in the new library into the Reference App, but didn't work as expected either.
The Monitor Activity seems to be working ok by notifying when the device has entered a new region. However, the Ranging Activity doesn't report any beacons, although didRangeBeaconsInRegion is getting called, always report zero beacons. Curiously, when the activity is paused (switching momentarily to another app) the logcat shows that now didRangeBeaconsInRegion does get called with actual beacons.
I'm kind of stuck right now because I don't know how to get any of libraries working on Android L, so again, any help would really be appreciated.
I'm using the latest Altbeacon build on 5.0+ and have no problem with it. in fact, I never used it on kitkat so i'm not really sure i can help but here is my working code which listen to iBeacons.
implement beaconConsumer:
public class MainActivity implements BeaconConsumer
init BeaconManager
beaconManager = BeaconManager.getInstanceForApplication(this);
if (beaconManager != null && !beaconManager.isBound(this)) {
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);
}
onConnect and start listner
#Override
public void onBeaconServiceConnect() {
beaconManager.setRangeNotifier(new RangeNotifier() {
#Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
if (beacons.size() > 0) {
Beacon firstBeacon = beacons.iterator().next();
}
}
});
beaconManager.startRangingBeaconsInRegion(new Region("com.example.app", null, null, null));
}
this code is working on 3 devices
Nexus 4 5.0.1
Samsung Galaxy s4 - Stock 5.0.1
Samsung Galaxy s4 - CM12 5.1.1
Old question, but maybe some people will try to find answer for higher systems where you have to ask for permissions. You need to ask for Manifest.permission.ACCESS_FINE_LOCATION before scanning. At least that was the problem I met. In my opinion lib should crash such cases at least and indicate the problem

Attempt to add read-only file at path file:///var/mobile/Media/PhotoData/Photos.sqlite?

I have just updated to the new Xcode beta 6.0 and when trying to compile for an ipad mini with iOS 8 I am getting a weird error in the console:
"Attempt to add read-only file at path file:///var/mobile/Media/PhotoData/Photos.sqlite?readonly_shm=1 read/write. Adding it read-only instead. This will be a hard error in the future; you must specify the NSReadOnlyPersistentStoreOption"
This happens when executing the following code:
if ([self.rootDelegate respondsToSelector:#selector(wImageRequiresAPhotoPicker:)]){
[self.rootDelegate wImageRequiresAPhotoPicker:(DWImage*)item];
}
And:
-(void)wImageRequiresAPhotoPicker:(DWImage *)img{
self.selectedWimg = img;
DWImagePickerController *imgPicker = [[DWImagePickerController alloc] init];
[imgPicker setDelegate:self];
[imgPicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imgPicker setAllowsEditing:YES];
[imgPicker setModalPresentationStyle:UIModalPresentationCurrentContext];
UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
popOver.delegate = self;
self.popoverImageViewController = popOver;
[self.popoverImageViewController presentPopoverFromRect:img.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
Does anyone have a clue of why this is happening?
Most likely a newly introduced bug in iOS 8 beta 2. Let's see how it develops.
It seems that ALAssetsLibrary requests internally read & write access to Photos.sqlite database, and it can only gain read access. I'm receiving the same error with this call:
[self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
...
It is a core data error, and since my app does not use core data, and I receive the error when I access the photo library picker, I'm gonna say it is on Apple, and a bug. Apparently files are attempting to be added as read/write and they are read only. I'm pretty sure Apple should know this, since they set up the image picker. I'm just trying to access it.
self.pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

Simulator quits unexpectedly giving error, Springboard failed to launch error: -3

I am trying to make a basic Application with a background Gradient, Navigation Bar and a logo on it. When Launched in a simulator an error pops up, saying Springboard failed to launch error: -3
I am Using the Following two in code in the ViewController:-
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = #"Menu";
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(257, 3, 320, 44)];
UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"ic_home.png"]];
[image setFrame:CGRectMake(0, 0, 59, 36)];
[view addSubview:image];
[self.navigationController.navigationBar addSubview:view];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//Add gradient background
CAGradientLayer *bgLayer = [BackgroundLayer yellowGradient];
bgLayer.frame = self.view.bounds;
[self.view.layer insertSublayer:bgLayer atIndex:0];
}
not sure if this is the most technical answer but still...
Injectios is right, it's not your code (or at least my code never causes that) it's something to do with interface builder/putting files onto the simulator (from my experience).
Simply change the device that your building for and then switch back (for example, if developing for the 3.5" iPhone screen, click the 4" simulator and run, once it builds stop it and switch back to your target device) If you are using xcode 5 the list of devices is on the same toolbar as your Run and Stop buttons or go Product -> Destination
hope it helps
How about trying to delete the app from the simulator and restarting the simulator?
In my case, none of the above answers worked. So in my desperation I finally decided to revise all warnings and resolving them. It turned out that the root of the problem was that I was sending objects of wrong type to NSNumberFormatter and other classes/objects.
So in short: revise all your warnings and resolve all of them that mention pointer conversion problems.
Try reset the simulator
simulator -> reset contents and settings
It is worked for me

Resources