I'm trying to create a Plugin in MvvmCross that uses the UIActionSheet. But to use it I need to have the top View in iOS. I found in Android the IMvxAndroidCurrentTopActivity but i could not find a similar in iOS. Is there anything that i can use like this in iOS?
var activity = Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity;
if (activity == null)
{
throw new Exception("Cannot get current top activity");
}
I don't think there is an exact equivalent.
Plugins like PictureChooser work around this by using IModalHost from the presenter - e.g. see https://github.com/MvvmCross/MvvmCross/blob/v3.1/Plugins/Cirrious/PictureChooser/Cirrious.MvvmCross.Plugins.PictureChooser.Touch/MvxImagePickerTask.cs
Other plugins rely on statics or globals - e.g. see https://github.com/brianchance/MvvmCross-UserInteraction/blob/master/Chance.MvvmCross.Plugins.UserInteraction.Touch/UserInteraction.cs
For your plugin, you could require that users provide a custom interface in their app (e.g. in the presenter) or you could add something to IModalHost as a pull request.
Related
Why FBVisualComponent::GetQWidgetAddress() in Motion Builder SDK always return 0?
I want to get the address of qwidget inside a FBLabel, and call some native QT method on it.
However, I found that the method always return a 0.
I wonder if this method works.
I'm using MotionBuilder2019.
It seems that MotionBuilder uses QWidget encapsulated by theirselves, instead of native QT widgets like QLabel or QPushButton. It means that even if you can get the address of these QWidgets, you can do nothing to them. If you really want to make a nice user interface, just use the QT via FBNativeHolder.
I am working an storyboard/objective-c based iOS app with firebase authentication. I use cloud firestore to save user data - age, gender etc. When user reaches the app I check if user is logged in or not the following(similar) code
FIRUser *firUser = [FIRAuth auth].currentUser;
if (firUser) {
// user logged in
// fetch updated user date from cloud firestore
} else {
// NO logged in user
}
When user is logged in, they can navigate to other section of the app, otherwise they would see a signup/login page.
What it looks Navigating to different views usually means I have to call above code to figure out the logged in state again - which I do not want to do. I would like to create a user object with logged in user and data from firestore and pass it between view controllers.
Singleton seemed to do the job well and kind of ideal for my situation but I came across Typhoon!
First question is, is it still ok to use that framework? Seems a little inactive, but very amazing technology though.
Secondly here is my implementation of it - I have an assembly that looks like this
- (AuthenticatedUser*)authenticatedUser {
return [TyphoonDefinition withParent:[self user] class:[AuthenticatedUser class] configuration:^(TyphoonDefinition* definition){
definition.scope = TyphoonScopeSingleton;
}];
}
And this is how I am obtaining AuthenticatedUser instance
ModelsAssembly *modelsAssembly = [ModelsAssembly defaultAssembly];
// no default ModelsAssembly set
if( modelsAssembly == nil ){
modelsAssembly = [[ModelsAssembly new] activated];
[modelsAssembly makeDefault];
}
authenticatedUser = [modelsAssembly authenticatedUser];
To obtain the same initiated class in different views seems like I need to do the following:
use TyphoonScopeSingleton as definition.scope in the assembly
make the assembly default
I am wondering if someone could provide me with some guidance regarding this.
First question is, is it still ok to use that framework? Seems a little inactive, but very amazing technology though.
Answer:
Typhoon is still the best choice of of Dependency Injection library for Objective-C. It is feature complete, so new features are generally not added, however it is maintained and supported by AppsQuick.ly.
If you're working with Swift, Fiery Crucible is an excellent DI framework. It has most of the features of Typhoon, simple to use, and without the drawbacks of some of the other Swift frameworks.
To obtain the same initiated class in different views seems like I need to do the following:
use TyphoonScopeSingleton as definition.scope in the assembly
make the assembly default
I am wondering if someone could provide me with some guidance regarding this.
Answer:
This is not the correct approach. The idea is to have one instance of Typhoon, create at the composition root, and then it will live alongside your application for the life of the running (foreground or back-grounded) app.
We don't ask Typhoon for dependencies, we tell it to inject the dependencies to the controller, service or other class.
The only exception to this is when using the factory pattern, where we have a mix of static dependencies, alongside runtime arguments, for example: "give me the order view controller for this user". In this case we inject the assembly itself.
For iOS, Typhoon provides a way to bootstrap your assembly on startup, either with or without storyboards. The sample shows how to do this, along with this guide on storyboards.
If you face another obstacle after trying the above resources, please ask another specific question.
I just started messing around with Xamarin and I'm confused on two things. How to use it and if I'm searching the right keywords for help.
If I want to look up something can I look up the native iOS controls as an equivalent? I feel if I search "how to get value from ios picker" the answers are specific to objc-c. Even trying to look at the same properties I have no luck. The Xamarin Tutorials/ documentation I feel are disorganized and lacking. PickView isn't in the list of UI controls that have documentation.
I don't see any events for this PickViewer either in Xamarin Studio. I even try debug mode in Xamarin iOs but almost every property I try and check that seems it might be the answer gives me an "unknown member".
In this example, I have a Xamarin iOs pickviewer and can't figure out how to retrieve the value or even alert on a row selected which doesn't seem to work. I assume I can apply this to a list table as well?
Setting up the PickView list
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
pvBankRollAmounts.Model = new UIPickViewBetAmountOptions ();
}
So how can I get the value of what was selected in the UI? and what's the best way to find these answers on my own? Better Documentation somewhere?
Xamarin iOS sticks pretty closely to the Apple iOS model of doing things. It is actually beneficial to be able to read Obj-C (or Swift) so you can look at Apple's documentation and samples.
Xamarin has a PickerView sample as part of their sample app.
To get the Selected item, you need to override the Selected method in the Model class. This seems strange from a C# perspective, but it is a fairly common pattern in iOS, which commonly uses a Delegate pattern. You could create a custom event and raise it to be handled in your parent class.
public override void Selected (UIPickerView picker, int row, int component)
{
// row is the selected row
}
I am writing a bootstrap Firefox addon and need to register a new protocol/schema handler (e.g. foo:somthing). I have looked all over and I only see ways to do this using chrome.manifest, which bootstrapped add-ons cannot use.
So, does anyone know a way or is it possible to register a custom protocol handler in a bootstrapped add-on?
Yes, but you'll have to do the work that the add-on/component manager would do for you, in particular calling .registerFactory yourself.
There is already a test demonstrating how to register components in general, and protocol handlers in particular, at runtime yourself.
Although #nmair's answer is a good general thing I'll keep in mind, I was able to find a better solution to my own problem. I noticed that there was an HTML5 method that would try to ask the user to register a handler for a protocol/schema, and after picking around in omni.ja (firefox source code), I found it's definition. After fiddling around, I wrote this:
var handler = Cc["#mozilla.org/uriloader/web-handler-app;1"]
.createInstance(Ci.nsIWebHandlerApp);
handler.name='My Protocol';
handler.uriTemplate='chrome://myprotocol/content/launcher.xul#%s';
var eps=Cc["#mozilla.org/uriloader/external-protocol-service;1"].
getService(Ci.nsIExternalProtocolService);
var handlerInfo=eps.getProtocolHandlerInfo('myprotocol');
handlerInfo.possibleApplicationHandlers.appendElement(handler, false);
handlerInfo.alwaysAskBeforeHandling=false; // don't ask the user
handlerInfo.preferredApplicationHandler=handler; // set my handler as default
hi=handlerInfo;
var hs=Cc["#mozilla.org/uriloader/handler-service;1"].
getService(Ci.nsIHandlerService);
hs.store(handlerInfo);
Registers the protocol, no restart or components required.
The new Google Analytics SDK introduces a new subclass to UIViewController from which you have to inherit: GAITrackedViewController.
More info here: https://developers.google.com/analytics/devguides/collection/ios/v2/screens
This obviously clashes with MvxBindingTouchViewController, as you can only inherit from one class in C#.
What's the recommended way in getting this working?
MvvmCross's MvxTouchViewController's is special...
MvvmCross's MvxBindingTouchViewController is even more special...
But these are only special in that they inherit from standard UIViewControllers (UIVIewController, UITableViewController, UITabBarController, etc) and then they add functionality for:
ViewModel construction and the ViewModel property at the Cirrious.MvvmCross layer
construction and storage of Bindings at the Cirrious.MvvmCross.Binding layer
Take a look at some examples:
https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxTouchViewController.cs and https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxBindingTouchViewController.cs
https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxTouchTableViewController.cs and https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxBindingTouchTableViewController.cs
https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxTouchCollectionViewController.cs and https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxBindingTouchCollectionViewController.cs
In these you can hopefully see this involves a fair amount of cut and paste of code - although we do try to minimise it using extension methods. (If C# had multiple inheritance or mixins, we wouldn't need to do that - I'd love to have Mixins... but don't want multiple inhertitance ever!)
So.... if you want to add your own MvxXXXXXBindingViewController, then:
take your base XXXXX class,
inherit from it and add 'the stuff' to make an MvxXXXXViewController,
then take your MvxXXXXXViewController and inherit from it again to make your MvxBindingXXXXXViewController
publish to your blog and to a new GitHub repo so everyone else can piggyback off your hard work
job done
Advanced notes:
If you want to see the same thing in Droid, see Insert a Monogame view inside MvvmCross monodroid Activity
The TabBarController is also interesting - it's got some additional methods
At some point 'soon' (first half of this year) we will create VeeThree and this will switch the MvxViewController's to a non generic format - this is because MonoTouch now recommends against using Generics on iOS base classes - Rolf says it's safe most of the time, but when it causes bugs they are 'heisenbugs'.
There is also some dead old-iOS code in the current classes (ViewDidUnload) - this code will be culled in VeeThree too.