I'm using kotlin-multiplatform for iOS and Android targets.
I'm deserializing json string with timestamp inside: 2020-01-16T11:33:34.553Z
I would like to convert this timestamp to time in milliseconds (unix time). Is it possible to do this using kotlin native libraries?
I'm using kotlin multiplatform 1.3.72.
Yes, you can do it with native kotlin libs like this:
timeValue.toInstant().epochSeconds
where toInstant() is a function in the kotlinx.datetime library.
Related
NOTE: Please do not do a knee-jerk close recommendation based on "more code required for a minimal reproducible example" especially if you don't understand the question. If you follow my logic, I think you will see that more code is not required.
I'm doing some platform specific Flutter code where I have a platform method "stopRec" (stop recording) which awaits a byte array from the native host.
On the Dart side, it looks like this:
Uint8List? recordedBytes;
recordedBytes = await platform.invokeMethod('stopRec');
As you can see it's expecting to get a byte array (Dart Uint8List) back.
I've written the Android code and it works -- it tests out fine, the recorded bytes come back through and playback correctly.
This is what the Android (Java) code looks like:
byte[] soundBytes = recorder.getRecordedBytes();
result.success(soundBytes);
I hope you understand why "more code" is not yet necessary in this question.
Continuing, though, on the IOS side, I'm getting the following error when calling the platform method:
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: type
'List<Object?>' is not a subtype of type 'Uint8List?' in type cast
The Dart line where the error occurs is:
recordedBytes = await platform.invokeMethod('stopRec');
So what is happening is that it's not getting a the Dart Uint8List it expects sent back from IOS.
The IOS code looks like this:
var dartCompatibleAudioBytes:[UInt8]?
var audioBytesAsDataFromRecorder: Data?
// ..... platform channel section
case "stopRec":
self?.stopRec()
result(self?.dartCompatibleAudioBytes!) // <---- wrong data type getting sent back here
break
// ..... platform channel section
private func stopRec() {
myRecorder.stopRecording()
audioBytesAsDataFromRecorder = myRecorder.getRecordedAudioFileBytesAsData()
dartCompatibleAudioBytes = [UInt8] (audioBytesAsDataFromRecorder!)
}
I have tested the same IOS implementation code as a stand-alone IOS app that is not connected to Flutter, so I know that at the end of the the stopRec() method, the dartCompatibleAudioBytes variable does contain the expected data which plays back properly.
I hope you can see why "more code" is still not necessary.
The Dart code works
The Android code Works
The Dart code works together with the Android Code
The IOS code works
The IOS code does NOT work together with the Dart code
Using what I've shown, can anyone see immediately why the expected data type is not making its way back through the method channel?
According to the documentation, you should be using FlutterStandardTypedData(bytes: Data) in swift in order for it to be deserialized as Uint8List in dart.
I have a Kotlin Multiplatform project setup with Android & cocoapods for iOS.
I have a file Extensions.kt in commonMain/src with the following function:
fun String.isValidEmail(): Boolean {
return validate(ValidatorRegex.EMAIL)
}
I am able to access this function in Android as a String extension:
"abcd#gmail.com".isValidEmail()
But in iOS using Swift, I need to call it as a static method of another class:
ExtensionsKt.isValidEmail("abcd#gmail.com")
It should convert that commonMain/src method to a Swift extension of String instead of a class with a static method.
Am I missing any configuration?
You're doing everything right here. Unfortunately, this option is not available for now. Extensions conversion may be performed correctly for some classes, but Swift's String is not the one. This is a known inconvenience, and K/N team is working hard to make it better.
I do data compresssion with libcompression.tbd, which was introduced
in iOS 9.0. There appeared libParallelCompression.tbd in iOS 11.0. But I can't find any information about it, and library header looks like that:
symbols: [ _BXDiff5, _BXPatch5, _BXPatch5InPlace, _BXPatchFile, _CachePatch,
_DirectoryDiff, _DirectoryPatch, _ISparseArchiveStreamCreate,
_ISparseArchiveStreamDestroy, _ISparseArchiveStreamRead, _PCompressFilter,
_PackagePatch, _ParallelArchiveExtract, _ParallelArchiveGenerateBOM,
_ParallelArchiveGenerateMSUBOM
...
I have strong suspicion that libParallelCompression is for audio processing.
How to detect the purpose of libParallelCompression.tbd?
Do you know compression libs for iOS, faster that libcompression.tbd?
I just create my first app extension using XCode 7.1. One code file containing the code below is shared with both targets:
var str = "";
var l = str.count; //Compile error for extension target App: count is unavailable: There is no ...
The reason for this compile error seams to be that App extension compiles with swift 1.2 while the container target compiles with swift 2.0.
One solution would be importing the content App into the extension App doesn't appear to be a good solution from what i read about it. Sharing the code between targets can be difficult if both are not compiled using the same compiler.
I just run through all target settings and didn't find nothing that could be changed.
Can't find any post about this problem, witch is not so uncommon, so it is must likely i am interpreting something in a wrong way.
The only solution i can think of is using NSString instead of String but that is just an workaround for one class type. More problems of this kind will emerge in the future.
In Swift 2 it's
str.characters.count
Use str.characters.count to get String length in Swift 2
I record the sound of on iPhone using AvAudioRecorder (xamarin). How convert audio file to .FLAC format using C# (for google speech api) ?
There isn't a C# wav-to-flac converter right now.
You could simply use FLACiOS with wav-to-flac files embedded into a project in xcode.
Then use native binding of
public partial class NativeMethods
{
[DllImport("__Internal",
EntryPoint="convertWavToFlac",
CallingConvention = CallingConvention.Cdecl)]
public static extern int FlacEncode(
[MarshalAs(UnmanagedType.LPStr)] string wav_file,
[MarshalAs(UnmanagedType.LPStr)] string flac_file) ;
}
and just use bound native method to convert your wav to flac.
There are number of open source C# managed encoders, please check FlacBox or C# Flake. See also Discussion on the latter