iOS - Multiple apps using FMOD - audio only works in the first app to be run - objective-c

I'm working on an existing app that I did not develop, and it plays its audio using FMOD.
From the looks of things, previous versions of the app were written to use AVAudioPlayer instead, and there are build options to use either.
The most recent versions use FMOD though, because a lot of the functionality is only included when built using the FMOD version.
The problem comes when I use one of the existing apps first, then try to run this new one that I'm developing.
If I run one app, then leave it in the background and run the second app, the sound in the second app doesn't play at all. I can go back to the first app and play sound without problems. If I kill both apps, and start the other one first, then it works perfectly.
If I build the app using the AVAudioPlayer option, then I don't get this problem, but also all of the functionality that was written for the FMOD version is not there. I can therefore prove that it is something to do with FMOD, but can't figure out what.
EDIT:
Have done a little more digging, and I'm getting two FMOD errors:
Firstly, when I run:
result = fmodSystem->init(4, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, NULL);
I get error 51 - "A socket error occurred. This is a catch-all for socket-related errors not listed elsewhere."
Secondly, when I run:
result = fmodSystem->createSound((const char *)[audioData bytes], FMOD_SOFTWARE | FMOD_OPENMEMORY, &exinfo, &fmodSound);
I get error 79 - "This command failed because System::init or System::setDriver was not called."
The second seems to be because the init failed.

This was answered via Twitter, therefore I'll put the answer here myself, however, if Stuart would like to answer it himself here, then I'll vote that as the answer.
The answer is to disable: FMOD_INIT_ENABLE_PROFILE, because that can only run in one app at a time:
Therefore, this:
result = fmodSystem->init(4, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, NULL);
Should become this:
result = fmodSystem->init(4, FMOD_INIT_NORMAL, NULL);

Related

How to add double tap detection to sample app gatt_sensordata_app?

I am developing an Android app that gets data from Movesense using the GATT profile from the sample app GATT Sensor Data App here.
I followed the tutorial available here. Building the app and getting the DFU worked fine. I can get IMU, HR and temperature data with no issues.
Now I'd like add a tap detection feature to my app. I understand that I have to subscribe to 'System/States', but first I need to be able to receive the system state data.
I understand that I need a modified DFU for that, but I don't understand what changes I should make in which files of the gatt_sensordata_app before rebuilding and generating the new DFU.
What changes should I make in order to broadcast /System/State data?
(I usually just deal with Android so apologies for the very basic question.)
I tried adding #include "system_states/resources.h" to GATTSensorDataClient.cpp but I don't know how to continue.
The normal data straming in the gatt_sensordata_app uses the sbem-encoding code that the build process generates when building the firmware. However /System/States is not among the paths that the code can serialize. Therefore the only possibility is to implement the States-support to the firmware.
Easiest way is to do as follows:
In your python app call data subscription with "/System/States/3" (3 == DOUBLE_TAP)
Add a special case to the switch in onNotify which matches the localResourceId to the WB_RES::LOCAL::SYSTEM_STATES_STATEID::LID
In that handler, return the data the way you want. Easiest is to copy paste the "default" handler but replace the code between getSbemLength() & writeToSbemBuffer(...) calls with your own serialization code
Full disclosure: I work for the Movesense team

How do I access logs from the past day with os_log from Apple Watch?

I'm trying to troubleshoot an issue on watchOS.
I'm not sure how to reproduce the problem I'm seeing, but I do encounter it occasionally during testing on a real device in the wild, so I'm trying to use os_log in order to diagnose the problem after the fact.
As a first step, to make sure I understand how how to write to the log and access it later, I've attempted to log an event any time the app first loads.
In the ExtensionDelegate.swift file for my app, I added this:
import os.log
extension OSLog {
private static var subsystem = Bundle.main.bundleIdentifier!
static let health = OSLog(subsystem: subsystem,
category: "health")
}
Then, I updated the applicationDidBecomeActive delegate function with this:
func applicationDidBecomeActive() {
os_log("App Started",
log: OSLog.health,
type: .error)
}
I know it's not really an error message, but from what I've read, messages that are not .error are not written to saved to the log for later. I want to make sure it gets written to the log like a real error would.
I installed the sysdiagnose profile, then installed the the most recent version of my app.
After testing the app for the day, I attempted to export the file. Following the instructions I've found elsewhere, I produced a sysdiagnose on Apple Watch by holding the Digital Crown and Side button for two seconds (and felt the haptic feedback when I released).
Then, I put the watch on the charger for a few minutes per the instructions here, which recommended 15 minutes.
I opened the Watch app on my paired iPhone, then went to General > Diagnostic Logs and downloaded the sysdiagnose from Apple Watch, and sent it to my computer with AirDrop.
This gave me a tarball file (for example, sysdiagnose_2021.03.05_17-01-57-0700_Watch-OS_Watch_18S801.tar.gz). Once I decompressed that, I had a folder of lots of files and subfolders.
After poking around in this folder, I figured my best bet was to look in the system_logs.logarchive file. I opened that in the macOS Console app, set the Showing dropdown to All Messages, and looked around the time I opened the app. I didn't see any log output from my app.
I also filtered for "App Started" (the log message from my app) and didn't find anything.
Then, I filtered by category for "health" and didn't find the event I had logged.
Is system_logs.logarchive the correct place to be looking for the log output from my app?
If not, where should I be looking? Or what am I doing wrong?
I really want a better understanding of how I can log messages on Apple Watch so I can view them later so I can make my Apple Watch apps more robust, but I'm at a dead end.
Am I looking in the wrong place? Or am I setting up the logging wrong? Or is it something else? I would appreciate any guidance about this!
According to the Apple Dev Forms, sysdiagnose allows you to view the logs on your apple watch.

Handling iOS 8's Changes To App Containers within Xamarin (alternative to Environment.GetFolderPath)

Per the thread started at (http://forums.xamarin.com/discussion/24860/documents-directory-has-moved-in-ios-8#latest), we are working to adapt our App to the recent changes make in iOS regarding accessing the iOS 8 file structure. We have reviewed and attempted the implementation of the code found within the iOS 8 Note at http://developer.xamarin.com/guides/ios/application_fundamentals/working_with_the_file_system/#Creating_Files_and_Directories, and while the results of the sample code does provide some environment
variables, some additional instructions and how to get the results to behave in the same manner as Environment.GetFolderPath would be helpful – or guidance on whatever the appropriate approach should be.
The following takes place after a Release archive is built and pushed to an iPad device running iOS 8.0 (note not 8.0.1). We are using the following code:
var documents = NSFileManager.DefaultManager.GetUrls
(NSSearchPathDirectory.LibraryDirectory,
NSSearchPathDomain.User)
[0].Path
And we get:
/var/mobile/Containers/Data/Application/8C4D70BC-7607-xxxx-xxxx-A503A061E1EF/Library
But when we try to write to files in this directory, we get the following error in the device log:
Sep 25 12:47:22 Cognilores-iPad kernel[0] <Notice>: Sandbox: SEXI_reader(1243) deny file-write-create /usr/share/CogniLore
Is anyone able to help us identify what is going wrong and what workaround we can use? This is a severe issue – our App crashes immediately after users upgrade to 8.0, and we need to get an updated version into the approval process as soon as possible.
Is anyone able to help us identify what is going wrong
The path you show does not match the path from the device logs. Are you sure they come from the same code ?
e.g. maybe another part of your application later try to access a different directory (and this is what you're seeing in the logs) ?
Some quick test shows that the code (below) works fine on iOS8 devices.
var urls = NSFileManager.DefaultManager.GetUrls (NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.User);
var path = urls [0].Path;
File.WriteAllText (Path.Combine (path, "myfile.txt"), "woohoo");

Worklight JSON Store, can we get race conditions?

Worklight 6.1 on both Windows (colleague) and Mac (me), building an a Hybrid app destined for Android device but to speed up development we do initial testing as Mobile Web App in Chrome browser on desktop.
We get a weird symptom that I'm trying to fine-down to a reproducible test case. I think I see different behaviours when stepping in debugger and just letting it run. Want to check whether a certain coding pattern could be the cause of the symptom before I go any further.
Fundamental question: should we wait for the resolution of a promise returned by a JSONSTore request for an action on a collection before issuing another request? more explanation below.
The overall intent is to load some data into the JSONStore, with some intelligent replace/merge action if a record is already present. Pseudo code:
for each record retrieved from back-end
if ( record already present in Store )
do some data merging
replace record
else
add record
The application code actually works like this, just considering the add() case, the problem manifests when the store is empty, all records need to be added
for each record to add
addPromise = store.get().add(record);
listOfPromises.insert(addPromise);
examine the list of promises recording any errors
That is there is no "wait" for add to finish before issuing the next add request. Hence in effect we've initiated a set of adds "in parallel" whatever that might mean in JavaScript in Chrome.
The code appears to run just fine, no errors reported. On android device it works reliably. In Chrome under normal running (no stepping in debugger) we end up with no reported errors but only one record inserted - indeed as though a snapshot of the initial "empty" store had been taken and each add is working on that "empty" copy.
After writing this I'm now pretty convinced that the coding pattern described above is vulnerable to a kind of race and that the better approach is build a list of documents to be added and insert them in a single operation.
A more detailed answer will be coming later, but I now know that this
the coding pattern described above is vulnerable to a kind of race and
that the better approach is build a list of documents to be added and
insert them in a single operation.
is true. In the browser the JSONStore does require that we wait for the result of one request before issuing another one. The recommended approach is
var dataToAdd = buildArrayOfDataToAdd(responseFromServer);
var dataToReplace = buildArrayOfDataToReplace(responseFromServer);
jsonstore.add( dataToAdd ).then( function() { jsonstore.replace( dataToReplace); })

NSTask subprocess stuck in _dyld_start

I use NSTask to run my helper application. On 99% one my customer systems this works fine, but two got back to me letting me know it doesn't. One of them was nice enough to let me look into the issue per remote desktop.
I tried a lot of different NSPipe/NSFileHandle combination for StandardOutput/StandardError to make sure the problem is not related filling up these buffers. Example 1 and 2. My guess is that it is not related because it works fine on so many systems and _dyld_start is too early on in the application lifecycle to fill up StandardOutput/StandardError.
Other notes about the problem:
Launching the helper app from the terminal works fine.
Attaching and detaching the gdb on the stuck process and after-worth it works fine and when it finished NSTask picks up work after -waitUntilExit.
Using fork(2) and execv(3) instead of NSTask is able to launch and run the helper fine.
The parent process is sandboxed but I think previous reports where non-sandboxed on Mac OS X 10.6/10.7.
Screenshot of the process Sample from Activity Monitor:
Any clues or debugging tips to figure out why the helper is stuck in _dyld_start are welcome!
Since nobody answered, I am throwing a few ideas. Maybe one of them is the answer – only guessing – but since clues and tips are welcome, you could take a look at:
the list of the loaded libraries in the crash dump (there may be a clue there)
any error that would happen in the child process (after the fork). However, I see why it could be difficult to get back any post-fork error.
If I recall correctly, NSTask calls posix_spawn(2). This may be a clue, since using fork(2) and execv(3) seems working, you could focus on the differences between NSTask and the non-blocking alternative. Clearly, something is happening at the very beginning that prevents the child from executing properly.
Are you sure it is stuck and not crashed? As far as the user could tell, your app your app wouldn't look like it crashed. Only the child process would crash.
As a last resort, you could try to look for any Mach exception occuring (if
any, that would mean an error, which you wouldn't be able to
recover anyway. But it would provide valuable clues nonetheless).
You can tell willing custommers to send you their sysdiagnose. To this goal, ask them to hit Command + Option + Control + . + Shift to wait a few minutes. Soon after, their finder should pop a window to reveal a file named: sysdiagnose_timestamp_.tar.gz. Kindly ask them to mail it to you. Mine is around 5 MB. More details on the sysdiagnose man page.