Default instance(maybe static) of Messenger plugin like MVVM Light - xamarin.ios

Is there an equivalent in MVVMCross to MVVM Light's Messenger.Default instance(for standalone projects that don't comply with MVVM in Xamarin.iOS).
After looking at threads such as this, this, this
I decided to add the "MvvmCross Messenger" plugin to the PCL and iOS project. Thought I'd have to register the Hub and resolve it from the PCL and iOS projects with something like
// Registering in ViewDidLoad() of iOS project
Mvx.RegisterSingleton<IMvxMessenger>(new MvxMessengerHub());
// Try to resolve and subscribe in PCL and iOS project - both have nuget packages added
_messenger = Mvx.Resolve<IMvxMessenger> ();
_token = _messenger.SubscribeOnMainThread<MyMessage> ((message) => {
OutputLabel.Text = message.Number;
});
However I get a null reference exception right at Mvx.RegisterSingleton. Not too sure what I'm missing. All I'm looking for is the Messenger to function. Do not want any other part of MVVM in this project for now

In MvvmCross we made our messenger optional - so it's in a plugin.
If you want to use it standalone, then you can boot the plugin system using code like that shown in the CrossLight demos - see N=30 and N=39 in http://mvvmcross.blogspot.co.uk/ - and see the android-only demos in https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/CrossLight/PluginUse/NoBinding/Setup.cs
For iOS, you'll probably need some one-time init code something like:
if (MvxSimpleIoCContainer.Instance != null)
return;
var ioc = MvxSimpleIoCContainer.Initialize();
ioc.RegisterSingleton<IMvxTrace>(new MvxDebugOnlyTrace());
var manager = new MvxLoaderPluginManager();
var registry = new MvxLoaderPluginRegistry(".Touch", manager);
ioc.RegisterSingleton<IMvxPluginManager>(manager);
The code for the messenger itself is in: https://github.com/MvvmCross/MvvmCross/blob/v3.1/Plugins/Cirrious/Messenger/Cirrious.MvvmCross.Plugins.Messenger/MvxMessengerHub.cs
Alternatively... if you don't want Mvx code for binding, dispatcher, etc, then it's probably easier to just use something like the excellent TinyMessenger - https://github.com/grumpydev/TinyMessenger

Related

Why my custom C# extention does not execute when deployed to Spotfire WebPlauer/Consumer

I have a simple custom Add-in that just displays a message to the user.
namespace GeorgiSpotfireCustomExtention
{
public class GeorgiEvent : CustomApplicationEventHandler
{
protected override void OnApplicationInstanceCreated(AnalysisApplication application)
{
base.OnApplicationInstanceCreated(application);
MessageBox.Show("On Application Instance Created");
}
}
}
That is my CustomAddIn class:
public sealed class CustomAddIn : AddIn
{
// Override methods in this class to register your extensions.
protected override void RegisterApplicationEventHandlers(ApplicationEventHandlerRegistrar registrar)
{
base.RegisterApplicationEventHandlers(registrar);
registrar.Register(new GeorgiEvent());
}
}
I am just trying to learn the package deployment process. When I am running it locally - in the installed Spotfire Analyst client it displays the message just fine:
However, when I package the extention, add it to the server (via the "Deployments & Packages" section, adding the "spk" file and then saving the area, the message is not shown when I try to open a document in the WebPlayer/Consumer.
Notes: I am choosing "TIBCO Spotfire Any Client" for my intended client in the Package Builder when building the spk file.
from the Spotfire Wiki (emphasis mine):
WinForms graphical user interface is a component of the .NET Framework and not something supplied by Tibco Spotfire. It's not recommended to implement solutions using Forms, but sometimes it could be handy when debugging. There is no commitment that it will work in future versions of the Analyst client. Forms are not supported on the Web Player.
the example listed on the wiki is for IronPython, but presumably the same holds true for C# extensions.
Correct. My assumption, and I don’t really know a lot about .NET, so this is not absolute, is that the form is rendered on the machine executing the code. In the case of your example above, the dialog would pop on the Node Manager host. If you’re really set on using an alert like this, you can accomplish it in JavaScript with an ‘alert()’. There is probably a way to render dialogues o in the web client too, but I don’t know it offhand.

There is a crash when I use MimeKit in Xamrain.IOS

Intalled the Mime Kit and MailKit to packages folder of xamrion.IOS, and try to use them to send an email. It works, but there is a crash when running new MimeMessage()
How to fix this issue.
I am a super beginner with IOS AND Xamarin, thanks very much for your help.
About 6 or 7 lines unable to locate assembly 'I18N' (culture:'')
Log:
2017-07-27 16:18:05.103 AAAA.iOS[523:215341] Xamarin.iOS: Unable to locate assembly 'I18N' (culture: '')
async public void sentEmail(string fileName, string addressEmail)
{
var message = new MimeMessage();
System.Diagnostics.Debug.WriteLine(" SendMail MimeMessage ");
First off, if you are using the simulator you will not be able to send emails using anything that depends on Apple's mail app because it is not installed on the simulator.
If that's not the case, i would recommend using UIMessage instead. Xamarin has great documentation on how to create a pop over view to compose an email and send wit from inside your custom application.
EDIT:
here is the the link to the Xamarin tutorial on sending emails.
You need to go into your iOS Project Options -> iOS Build options and then enable the i18n assemblies to be included.

How to programmatically open the Bluetooth settings in iOS 10

I'm trying to access the Bluetooth settings through my application using swift.how can access bluetooth setting?
Xcode version - 8.0
swift - 2.3
iOS - 10
func openBluetooth(){
let url = URL(string: "App-Prefs:root=Bluetooth") //for bluetooth setting
let app = UIApplication.shared
app.openURL(url!)
}
Swift 3.0: working up to iOS 10
Note: This URL is "private API". The app will be rejected by App Store reviewers if used.
You will not be able to use the solution by #Siddharth jain. The Problem: The app will be rejected by Apple with a warning that you should never use non-public APIs anymore. Otherwise, you could risk your developer program.
As far as I know, all you can do is open the iPhone settings in general (or get lead to your app settings if there are some. To do so you need the following code
guard let url = URL(string: UIApplication.openSettingsURLString) else {
// Handling errors that should not happen here
return
}
let app = UIApplication.shared
app.open(url)
By this, you will always get a URL you can use without any problems with apple review.
Until now you cannot access to bluetooth settings from your app from iOS 10.
you can see the following link to keep your mind at peace.
https://forums.developer.apple.com/message/146658#146658
Opening the Settings app from another app
Now that iOS 15 seemed to have broken auto-reconnect for known Bluetooth devices (other than audio gadgets), it's extremely annoying. If someone finds a solution, App Store-safe or not, I'm all ears.

Xamarin iOS HockeyApp best practice setup?

I'm attempting to get HockeyApp to work in my iOS Xamarin Forms app. I installed the iOS HockeyApp component (v4.1.0), and the getting started information for shows the following:
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
var manager = BITHockeyManager.SharedHockeyManager;
manager.Configure("Your_App_Id");
manager.StartManager();
}
When I try this, BITHockeyManager.SharedHockeyManager is null.
I've tried to wrap these lines in HockeyApp.Setup.EnableCustomCrashReporting() and Setup.EnableCustomCrashReporting() as is referenced in this post, but Setup doesn't exist in the namespaces I have.
What am I missing to properly enable HockeyApp in iOS?
Whoo hoo! Figured it out finally! I had the linker options set to link 'All assemblies' because of a suggestion from the New type registrar in Xamarin.iOS 7.2.1, errors MT5210 and MT5211 thread. I was seeing the 'Native linking failed...' error and switching to 'All assemblies' initially fixed it.
Switching to 'Link SDK assemblies only' fixed both problems

Hosting and initialising multiple MVVMCross ViewModels for the MvxTabViewController

I need to create a Tab view in iOS. I tried to do this by simply adding a UITabBar to an MvxViewController but I could not get that to work (See this question if interested)
I am now trying to go use the approach MVVMCross and Apple seem to push me towards, a TabController.
In our Core project we have 4 ViewModels that are displayed from one or more places using a ShowViewModel call and are initialised with a customerNumber.
CustomerViewModel
CustomerOrdersViewModel
CustomerHistoryViewModel
ReturnsViewModel
In Android and Windows Store we have separate Views for each of these ViewModels. I do not want to change our Core implementation to support iOS. I will create a new ViewModel called TabbedCustomerViewModel and that will have 4 properties, one for each of the hosted ViewModels.
Using a custom MvxTouchViewPresenter registered in the iOS project I can listen for requests to Show one of the Customer views and then switch the Request to TabbedCustomerViewModel. I have that working, the new ViewModel gets created and the initialisation paramaters that would have been passed to the original VM are passed to the intercepting VM's Init method.
The problem I am having is knowing how I should be initialising the hosted VMs. I assume I am going to have to ctor, init and Start them manually. Has anyone got any thoughts on how to do this?
The N-25 Tab Tutorial does not have to worry about this as its hosted VMs are not standalone so don't have Init and Start dependencies
I have the initialisation of the VMs working now too. When the View loads it checks if it is within a Tabbed UI by looking at the ParentViewController.
If it is it calls a custom method on the new TabbedCustomerViewModel. I have copied the code that MVVMCross use and added it to the new Method
try
{
mvxViewModel.CallBundleMethods("Init", this.initialisationParameters);
if (reloadedState != null)
{
mvxViewModel.CallBundleMethods("ReloadState", reloadedState);
}
mvxViewModel.Start();
}
catch (Exception exception)
{
throw exception.MvxWrap("Problem initialising viewModel of type {0}", mvxViewModel.GetType().Name);
}
The initialisationParameters and reloadedState are stored by TabbedCustomerViewModel when it is initialised so that it can pass it down to the ViewModels it is hosting

Resources