MonoTouch Binding library built using Objective-C static library doesn't call corresponding objective-C method when C# counterpart is called - xamarin.ios

I've a static library (say myLibrary.a) built from Objective-C Xcode project.
I'm trying to re-use it in Mono Touch iOS application. Following documentation, I built an iOS library project in Xamarin Studio, added myLibrary.a and linked and exported all the methods I want to be available using MyLibrary.cs as shown below. When I build the project it produces myLibrary.dll
[BaseType (typeof (NSObject))]
interface TouchTestDriver {
[Static]
[Export ("initMyLibrary")]
void InitMyLibrary ();
[Static]
[Export ("startDoingSomethingInteresting:")]
NSUrl StartDoingSomethingInteresting (NSUrl url);
}
Then I built an iOS app (solution) using Xamarin Studio, and included myLibrary.dll in the resources. The classes from myLibrary.dll are visible, so I could do something like this:
using MyLibrary;
and in AppDelegate.cs FinishedLaunching() method, I call the method
MyLibraryLib.MyLibrary.InitMyLibrary();
When the app is run in Simulator, it all seems to work fine, but its not calling the objective-C method initMyLibrary(). I confirm this by putting NSLog(), and exit(0). The app doesn't log anything not does it exit.
Am I missing anything? Is there any documentation for this usecase (other than the BindingSample, which I have followed several times w/o any success)

Related

Using an Objective C framework, which is inside a Swift framework, in a Xamarin iOS project

I have a Objective C framework. (This framework is working properly with a Swift project)
Then I have a Swift framework. This framework has used the previously mentioned Objective C framework. (This Swift framework also working in a Swift project)
Now I am trying to use that Swift framework inside a Xamarin iOS project.
I have created a Binding Library project in my Xamarin iOS project and under the Native Reference, I have added both those Swift framework and Objective C framework fat files.
I have updated the ApiDefinition file accordingly as well.
But when I run the application it launch in the phone and exit without giving any error. I'm glad if application crashed with an error. But it doesn't and I'm clueless now. Any thoughts?
Below is how I'm trying to access the methods in those frameworks inside my Xamarin iOS project
using BindingSwift;
// More codes here
public override void ViewDidLoad()
{
base.ViewDidLoad();
var myClass = new AroshaMathPerformer();
var result = myClass.DoTheMath;
Console.WriteLine("# Result = " + result);
}
But, if I add a breakpoint, it doesn't even hit at the run time before the application exits.
Assuming that everything you did is in the question, then it is expected not to work. Swift libraries are not officially supported on Xamarin.iOS. Some people made them work with these steps: https://medium.com/#Flash3001/binding-swift-libraries-xamarin-ios-ff32adbc7c76
In such a case, you can find the real reason by going to
Settings -> Privacy -> Analytics -> Analytics Data -> And find the log
file with your bundle ID and the crashed occur date/time.
The error show to me was related to #rpath/ but actually it solved after signing the bundle with a valid provisioning profile.
For those who are interesting, you can visit here to find out my experience of implementing this whole scenario mentioned in the title.

AppsFlyer Xamarin iOS binding, null reference exception

https://github.com/AppsFlyerSDK/XamariniOSBinding
Is anyone able to get this repo running?
I am hitting an null reference exception on startup because the tracker object is null - although this is bound as a static in the API Definition
// +(AppsFlyerTracker *)sharedTracker;
[Static, Export ("sharedTracker")]
AppsFlyerTracker SharedTracker ();
I was having the exact same issue and I found out what the problem is. I was testing this using the simulator.
The AppsFlyer SDK returns null for the AppsFlyerTracker.SharedTracker() method if the app is running on the simulator. Make sure that you run the app on a real device, and that you check for a null before calling methods on SharedTracker() otherwise you'll get a NullPointerException from Xamarin.
Make sure you've added a reference to AppsFlyerXamarinBinding.dll in your project's references, under .Net Assembly.
The dll file can be found in the project's Bin/Debug folder (you'll have to build the binding project first in order to generate an updated dll file).
Also, add "using AppsFlyerXamarinBinding" in your delegate.

Win8 app CLI library integration issue

I have a Win8 app that is purely native (c++) and I've already used a library that is written using managed code AFAIK. No issues there, I created objects and addressed them using C++/CX with ref counted pointers etc.
I need to add a new library, I referenced it as I did previously, but when I declare and object and try to address it I get:
error C3624: 'System::Object': use of this type requires a reference to assembly 'mscorlib'
Using #using <mscorlib.dll> is not a solution obviously, because WinRT does not support #using of a managed assembly.
When I look up the definition of the class I'm using in Object Browser I see that it's inherited from System::Object. The previous library had a class that was inherited from Platform::Object which is valid for C++/CX.
I already contacted the developers of current library I'm trying to use, but it takes a lot of time for them to respond.
Can I work around this issue? What are the possible courses of action?
UPD: Can I ask the developers to rebuild a library for C++/CX?
I do not believe this is going to work in the general case, unless the C# library is a PCL (portable class library). If it leverages anything that is not in the WinRT .NET client profile, it simply will not work.
If it is a PCL, what you can do is write a C# Windows Runtime Component that itself has a reference to this third-party library and wraps the necessary functionality. Then you reference that C# Windows Runtime Component from your C++/Cx application.

MvvmCross registering interfaces using IoC in Xamarin iOS7 and XCode 5

I'm having an issue activating the IMvxMessenger using IoC. (Mac, Xamarin Studio, iOS7, Mono 3.2)
I have downloaded NPlus1DaysOfMvvmCross and loaded the N37 Maps project.
Compiled the project and it works fine.
I then added the Cirrious.MvvmCross.Plugins.Messenger.dll to the project and the following code to the app.cs Initialize just below the service IoC call.
CreatableTypes (typeof(IMvxMessenger).Assembly).AsInterfaces ().RegisterAsSingleton ();
I receive and error when compiling that says:
Failed to resolve parameter for parameter id of type Guid when creating Cirrious.MvvmCross.Plugins.Messenger.MvxSubscriptionToken
IMvxMessenger is a plugin and does not need to be registered for IoC in the way you are doing it. Plugins get registered by creating a bootstrap class for each of the plugins you want to use in your project like so:
public class MessengerPluginBootstrap
: MvxPluginBootstrapAction<Cirrious.MvvmCross.Plugins.Messenger.PluginLoader>
{
}
Some plugins with platform dependent parts, such as the Visibility Plugin, need to be registered in a different manner on iOS, because it is silly:
public class VisibilityPluginBootstrap
: MvxLoaderPluginBootstrapAction<Cirrious.MvvmCross.Plugins.Visibility.PluginLoader, Cirrious.MvvmCross.Plugins.Visibility.Touch.Plugin>
{
}
This way you should be able to use the types inside of the Plugin using IoC.
This doesn't sound like it's anything to do with ios7
The line of code
CreatableTypes(typeof(IMvxMessenger).Assembly)
.AsInterfaces()
.RegisterAsSingleton ();
will:
take all the creatable types in the assembly (ie any non-abstract types with a public constructor)
will then find their interfaces
will then create a new instance and register that as the singleton implementation for the interfaces.
For the Messenger plugin, that includes trying to new and register an MvxSubscriptionToken as an IDisposable singleton - although this fails as the public constructor for MvxSubscriptionToken requires a Guid (and you haven't told MvvmCross how to supply that - so the construction fails)
If you did want to just register specific types in an Assembly, then normally you'd add a EndingWith("PostFix") clause - like the default Mvx nuget templates do with Services as the postfix.
If you did want to just register a single specific class from an Assembly, then you'd often just do that as:
Mvx.RegisterSingleton<IThing>(new Thing());
However, for plugins - which are just a convention-based set of rules placed on top of IoC - what you normally want to do is to call EnsureLoaded() on the plugin manager for the PluginLoader for that plugin.
The easiest way to do that is to include a Bootstrap file in the UI project - see the examples in N=8 - https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-09-Location%20And%20Message/Location.Touch/Bootstrap - your application's Setup will use Reflection to find that Type and will then call EnsureLoaded on the plugin for you.
For more on IoC in MvvmCross, see https://github.com/slodge/MvvmCross/wiki/Service-Location-and-Inversion-of-Control
For more on plugins, see https://github.com/slodge/MvvmCross/wiki/MvvmCross-plugins
Make sure the plugin is installed in the Core project AND the Android project.

Automapper : Automating Profile registration not using global.aspx

I am using AutoMapper in a distributable C# DLL for my ORM logic.
This DLL is consumed by different development teams for the web projects. Some of these web projects are MVC and some are web forms.
If there a way to have my DLL ensure that all the mappings have been register on application-start without having each team put the calls in their global files?
I have profiles all setup, but want this step to be hidden and always done.
Thanks
The only thing I can think of is to have a static constructor for a class in your dll where you will initialize automapper.
public class MyOrmClass
{
public static MyOrmclass()
{
//initialize automapper
}
}
I have an open source library that might help you with it, but you might have to do some small changes on each client

Resources