Here is some watchOS code I have working on the Similator(Watch):
.....
let interval = 60.0
NSTimer.scheduledTimerWithTimeInterval(interval,
target: self,
selector: #selector(InterfaceController.timerDidEnd(_:)),
userInfo: nil, repeats: false)
.....
func timerDidEnd(timer:NSTimer) {
print("Time is over! Please wake up!")
}
From Xcode I run the app, the first part of the code above gets executed. Then I hit Command-Shift-H and the app goes in the background.
After one minute I see in the debugging console the message: Time is over! Please wake up!
All works as I expect. My question is:
What should I write inside the function timerDidEnd(), in order to have the app wake up from the background on the simulator, rather than just printing the current message in the debugger?
There's nothing you can write inside a timer action that will bring an app to the foreground. Only the user can resume an app.
If you think about it, it would confusing and disruptive for the user if an app could programmatically bring itself to the foreground whenever it wanted.
The only way to resume an app is by the user reacting to a notification. This is similar to what happens on the phone when the user taps notification actions from the home screen.
Related
I'm trying to create a Watch-App where I download data (around 30 MB).
Therefore I create a URLSession with a background configuration like so:
let config = URLSessionConfiguration.background(withIdentifier: "<some-id>")
self.session = URLSession(configuration: config, delegate: self, delegateQueue: .main)
and then start the download:
let request = URLRequest(url: "<some-url>", method: .GET)
self.task = session.downloadTask(with: request)
self.task.resume()
Since the user is not gonna stare at the watch for 5 minutes, I want to notify him with some haptic feedback when the download finished.
Therefore I wanted to use the handle(_:) function of the ExtensionDelegate. According to the documentation, this should be called with a WKURLSessionRefreshBackgroundTask when the download finished:
The system creates a background URLSession task when any of the following events occur:
Authentication is required to complete a background transfer.
All background transfers associated with a session identifier have completed (either successfully or unsuccessfully). https://developer.apple.com/documentation/watchkit/wkurlsessionrefreshbackgroundtask
This handle(_:) method is only called if I close my app though (pressing the crown), not when i lower my wrist to lock the screen.
I also noticed, that if I look at the watch again, the callbacks for urlSession(.. didWriteData ..) are not working anymore.
Am I missing something or is this even expected behaviour? I'm testing on a real Apple-Watch Series 4 with WatchOS 5 installed.
I am using Laravel Dusk to write browser tests for a Laravel 5.7 application. In the test I am navigating to the page and clicking a button which triggers a confirm dialog. I am trying to test that dismissing the dialog does not change the page url.
I have tried adding $this-expectException(UnexpectedAlertOpenException::class) before running the test to try to make the code understand a dialog should be shown
{
$this->expectException(UnexpectedAlertOpenException::class);
$this->browse(function (Browser $browser) {
$browser->loginToWave()
->goToSystemsEdit();
$browser->waitFor('#delete-systems-button')
->click('#delete-systems-button')
->assertDialogOpened('This will delete the system. Please seek advice before doing this. Continue?')
->dismissDialog()
->assertPathBeginsWith('systems/edit');
});
}
I expect the test to dismiss the dialog and check the path assertion.
What is actually happening is that an UnexpectedAlertOpenException is thrown:
1) Tests\Browser\Systems\DeleteSystemTest::testSystemNotDeletedIfConfirmIsDismissed
Facebook\WebDriver\Exception\UnexpectedAlertOpenException: unexpected alert open: {Alert text : This will delete the system. Please seek advice before doing this. Continue?}
(Session info: chrome=71.0.3578.98)
(Driver info: chromedriver=2.45.615279 (12b89733300bd268cff3b78fc76cb8f3a7cc44e5),platform=Linux 4.9.125-linuxkit x86_64)
/var/www/html/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:140
/var/www/html/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
/var/www/html/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:547
/var/www/html/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:345
/var/www/html/vendor/laravel/dusk/src/Browser.php:261
/var/www/html/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:139
/var/www/html/vendor/laravel/framework/src/Illuminate/Support/Collection.php:418
/var/www/html/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:140
/var/www/html/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:69
/var/www/html/tests/DuskTestCase.php:68
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 :)
When debugging my app with the simulator, the routine didUpdateLocations is never involved. What I do:
In the simulator, I select Debug>location>Custom Location and the window with longitude and latitude pops up. When pressing ok, I would expect the didUpdateLocations to be called.
I use locMgr as a global variable in a ViewController-module:
locMgr = CLLocationManager()
and in the viewDidLoad-function includes the following sequence:
locMgr.delegate = self
if CLLocationManager.authorizationStatus() == .NotDetermined {
locMgr.requestWhenInUseAuthorization()
}
I have coded the didUpdateLocations-function as a method of my viewcontroller class. I also verified (debugger), that the requestWhenInUseAuthorization-routine is invoked during initialisation. So were is the problem, why is the didUpdateLocations protocol-routine not invoked?
dasdom solved the problem by suggesting: Why requestWhenInUseAuthorization doesn't prompt the user for access to the location?
Windows Workflow State Machine
has a state (AwaitingFeedbackState) with two transitions.
Transition 1) awaiting receive message from client within "Trigger" body, email activity within "Action"
Transition 2) CheckReminderEnabledActivity within "Trigger" body, delay and email reminder activity within "Action"
when CheckReminderEnabledActivity is true, the behaviour works fine, the work flow goes into delay but if it is
set to false, the workflow infinity loops in AwaitingFeedbackState, keeps hitting CheckReminderEnabledActivity.
Is there a way to disable this transition if CheckReminderEnabledActivity is set to false when process enters CheckReminderEnabledActivity for
the first time ?
I have fixed this by bringing in the delay and send reminder activity within the trigger body and have now also added if else as well. In the else body I have added a custom bookmark as per example here
https://code.msdn.microsoft.com/Windows-Workflow-50c3fba5