I'm trying to fetch the shared module version in my KMM project and use it for some internal logic.
On Android side of things I'm setting a variable in the BuildConfig with:
buildConfigField("String", "Version", "\"$version\"")
and fetching it from there:
BuildConfig.Version
I'm not sure how to do this for the iOS.
I see that there is an external dependency https://github.com/yshrsmz/BuildKonfig but I'm wondering if there is a way to do it without it?
Thanks.
In your shared/src/iosMain you will want a function as the following:
fun appVersion(): String {
return NSBundle.mainBundle.objectForInfoDictionaryKey("CFBundleShortVersionString") as String
}
This will pull the version that is defined as the CFBundleShortVersionString from your app level Info.plist
This entry will look like:
<key>CFBundleShortVersionString</key>
<string>1.0</string>
Related
I have an Ionic v1 / Cordova mobile app and I need to obfuscate all sources. For obfuscation of Javascript I have used https://github.com/javascript-obfuscator/javascript-obfuscator and for Java for Android I have used https://github.com/greybax/cordova-plugin-proguard. As I couldn't find any cordova plugin for obfuscation of Objective C and I decided to use https://github.com/preemptive/PPiOS-Rename.
However, after obfuscation with PPiOS-Rename, there seems to be a problem with obfuscation of cordova plugins and I'm unable to run the app correctly. If I remove the plugins from obfuscation process the app would work but I need to make obfuscated also the code of plugins.
Does anybody have experience with obfuscating the Objective C code of Cordova app please?
Thanks!
The problem that you have is that Cordova relies on a bridge between your app code written in Javascript and the underlying native code in order to function.
By obfuscating all of the Objective C code, the Javascript layer is unaware of this, and can no longer find the native class names it is looking for.
For example, let's suppose you have included cordova-plugin-device in your app.
Its <feature> definition for iOS maps the Device feature name to the CDVDevice class.
Let's suppose your Cordova app calls the plugin method device.getInfo().
This in turn invokes a call to cordova.exec() which calls the Device feature with the getDeviceInfo action.
Under the hood, Cordova looks up Device to find the native class name it's mapped to (CDVDevice) and then on the iOS platform it attempts to call the getDeviceInfo() member function on this class.
However, by running the PPiOS-Rename tool, you have obfuscated both the class name (CDVDevice) and the function name (getDeviceInfo()) so Cordova cannot find the class or function to invoke, so will throw an error.
In this case you'd need to exclude the CDVDevice using the filter option provided by PPiOS-Rename, for example:
ppios-rename --analyze -F 'CDVDevice' /path/to/program.app/program
If you wish to proceed with obfuscating the Objective C layer of your Cordova app, you will have to add exclusions for all of the class and function names which Cordova calls explicitly from the Javascript layer.
This includes any Cordova plugin interface classes in your project, and possibly classes belonging to the Cordova framework itself (as cordova-plugin-proguard does for ProGuard on Android.
I'm trying to access an iOS framework class from my NativeScript plugin.
Right now, this plugin only has a SampleClass with a test method that returns a number, but it will change soon. For now, what I'm trying to do is to call the class method from that native framework.
I have seen some examples where the plugin seed extends an iOS base class and creates everything there, but in this case, I want to use a .framework file.
I'm assuming this would be equivalent to use some .aar Android file. In that case, I've seen the call would be made with something like this
var c = java.lang.Class.forName("org.test.plugin.name.MyActivity");
So, I have copied the .framework file to platforms/ios, my question is about how to get this SampleClass method.
Also, I've seen some documentation that recommends the use of CocoaPods. I'm new to iOS development and still don't get this at all, but if my application won't use any native dependency, would this be necessary? Should I need another files? (got a default Info.plist and build.xcconfig)
Thank you for your answers.
Since you are using TypeScript, you have to either declare the classes like,
// iOS
declare var SampleClass;
// Android
declare var org;
then you may access all available packages / classes / methods directly.
// Android
const MyActivity = org.test.plugin.name.MyActivity;
// iOS
SampleClass.new()
If you like intellisense support for these libraries, then you may even generate declaration files for both iOS & Android libraries with the given steps in the docs.
The project I am working in is a Swift project. I needed to import a Objective C library and installation was only available (advertised) through 'CocoaPods'. I proceeded and installed the required library and built a bridging header.
Now for some reason I have a single random error deep in one of the files in the library. I'm 99% sure this is a problem with my set up as I can't find anyone else using Braintree (a rather popular payment service by PayPal) with the same problem.
Any ideas?
This looks like a consequence of overriding NSObject's description whose definition changed in iOS 8. (See http://www.redwindsoftware.com/blog/post/2014/08/20/NSObject-has-some-new-properties-in-iOS-8.aspx). Is there a more recent release of this library available for you to use?
I have a simple app which uses whirlyglobe framework (2.2). Otherwise, it is pretty basic program with Apple frameworks.
When I tried to validate the app (and during the distribution, Xcode complains that my app is using private API; specifically it calls "rootElement", and "attributeForFont:". I suspect these functions are part of WhilyGlobe component distribution.
What is the easiest way to remove those files from the framework? Do I need to have the source and compile the framework myself? Or is there a simpler way?
Solved. Here is what I did:
1) Searched in github repository of WhirlyGlobe and found the file that uses the functions which caused issue.
2) I did not need the functionality provided by the file that had the functions.
3) Removed the references (class instantiation) to the file from my project.
That's actually part of the KissXML framework and the implementation is in there. I suspect Apple's test is in error.
In any case, if you're not using the WMS functionality, you can probably drop it out just fine.
I'm trying to integrate InApp purchase & a native SDK provided by our publisher into a game made with Haxe & NME. I'm still using NME 3.5.5 & hxcpp 2.10.
I tried to use Native Extension as described here : http://www.openfl.org/developer/forums/programming-haxe/connecting-objective-c-haxe-ios-help/
and here : https://github.com/ericamccowan/Haxe_Extension_Test
I first tested it on windows, doing simple things in cpp, I had no problems passing and receving data.
I switched onto the mac, and tried to do the same for iOS, but I can't even manage to launch the game properly. I compiled the extension with the appropriate command, and then included the ".a" generated into the xcode project. But when I tried to run the game on an ipad via xcode, as usual, I got this :
(source: gyazo.com)
Here a look at what the project looks like
http://gyazo.com/ff6352a2bb7b2034c933b8305b711c48.png
Since the problem is localised on the "iOS_Native_register_prims()" in the Main.mm, I think it's a matter of xcode nor recognizing the native extension? I tried adding the iOS_Native.mm to the project, but then it threw an error because he was unable to include hxcpp.h
I realize I'm not really clear about all this, but that's because I don't quite understand how that should work... Does anyone ever tried something similar?
Thansk in advance for your help !
It sounds like you are missing a reference to the function iOS_Native_register_prims. The function declaration doesn't have to do anything other than return 0 but can also be used to initialize parts of your extension.
extern "C" int iOS_Native_register_prims () { return 0; }
The function name should match the project name so if you were creating a GameCenter extension it would be named GameCenter_register_prims.