Integrate LinkedIn with Monotouch - xamarin.ios

I have a problem in LinkedIn integration in Monotouch. i have integrated Facebook successfully using Logged In Session like as following :
internal void SaveAuthorization ()
{
var defaults = NSUserDefaults.StandardUserDefaults;
defaults ["FBAccessTokenKey"] = new NSString (facebook.AccessToken);
defaults ["FBExpirationDateKey"] = facebook.ExpirationDate;
defaults.Synchronize ();
}
or using like :
public class SessionDelegate : FBSessionDelegate
{
FacebookLoginViewController container;
public SessionDelegate (FacebookLoginViewController container)
{
this.container = container;
}
public override void DidLogin ()
{
container.ShowLoggedIn ();
container.SaveAuthorization ();
}
public override void DidLogout ()
{
container.ClearAuthorization ();
//container.ShowLoggedOut ();
}
public override void DidNotLogin (bool cancelled)
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?
link=T%3aMonoTouch.Foundation.ModelAttribute
}
public override void SessionInvalidated ()
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?
link=T%3aMonoTouch.Foundation.ModelAttribute
}
}
Now I want to use same for LinkedIn. how can i complete it.?
thanks in advance

Related

Xamarin.ios native ads admob

I have been trying to figure out how to implement native google ads (admob) in my Xamarin.iOS app. (not xamarin forms)
I have googled like crazy but can't find any good examples.
Does anyone have any code that they could share?
This is my code so far, but the adloader.delegate is always null..
public partial class ExploreController : UIViewController
{
readonly AdLoader adLoader;
public ExploreController (IntPtr handle) : base (handle)
{
adLoader = new AdLoader(
"ca-app-pub-3940256099942544/3986624511",
this,
new AdLoaderAdType[] { AdLoaderAdType.Native },
new AdLoaderOptions[] { new AdLoaderOptions() });
adLoader.Delegate = new MyAdLoaderDelegate();
var request = Request.GetDefaultRequest();
}
}
public class MyAdLoaderDelegate : NSObject, IUnifiedNativeAdLoaderDelegate
{
public MyAdLoaderDelegate()
{
}
public void DidReceiveUnifiedNativeAd(AdLoader adLoader, NativeAd nativeAd)
{
Debug.WriteLine("DidReceiveUnifiedNativeAd");
}
public void DidFailToReceiveAd(AdLoader adLoader, NSError error)
{
Debug.WriteLine("DidFailToReceiveAd");
//base.DidFailToReceiveAd(adLoader, error);
}
public void DidFinishLoading(AdLoader adLoader)
{
Debug.WriteLine("DidFinishLoading");
//base.DidFinishLoading(adLoader);
}
}

Registering AutoMapper with Unity fails

I have the following code to register Mapping (version 4.2)
public class ModelMapperProfile : Profile
{
protected override void Configure()
{
CreateMap<Case, CaseModel>();
CreateMap<CaseDetail, CaseDetailModel>();
}
}
public static class AutoMapperService
{
public static MapperConfiguration Initialize()
{
MapperConfiguration config = new MapperConfiguration(cfg =>
{
cfg.AddProfile<ModelMapperProfile>();
});
return config;
}
}
And I register the dependency using unity as follows...
public static void RegisterTypes(IUnityContainer container)
{
container.LoadConfiguration();
var mapper = AutoMapperService.Initialize()
.CreateMapper();
container.RegisterInstance<IMapper>(mapper);
}
My here service constructor..
public TaxLiabilityCaseService(IMapper mapper,
IUnitOfWork unitofWork,
IRepository<Case> caseR,
IRepository<CaseDetail> caseDetailR)
{
_mapper = mapper;
_unitofWork = unitofWork;
_caseR = caseR;
_caseDetailR = caseDetailR;
}
And I get the following error message..
The current type, AutoMapper.IMapper, is an interface and cannot be
constructed. Are you missing a type mapping?
Answers found here did not work for me
What am I missing here
Try following these steps (MVC5):
Get Unity Nuget package:
Unity.Mvc5
Create this class:
public class MapperConfig
{
public static IMapper Mapper { get; set; }
public static void RegisterProfiles()
{
var config = new MapperConfiguration(cfg =>
{
// add profiles here
});
config.AssertConfigurationIsValid();
Mapper = config.CreateMapper();
}
}
In the UnityConfig file (created by the package), add this:
public static void RegisterComponents()
{
var container = new UnityContainer();
container.RegisterInstance<IMapper>(MapperConfig.Mapper);
}
In the Global.asax, add these:
protected void Application_Start()
{
MapperConfig.RegisterProfiles();
UnityConfig.RegisterComponents();
}
You should be good after this.

Has anyone gotten Xamarin-Sidebar, MVVMCross & Storyboards to work together?

I've tried all permutations I can find on the web and just can't seem to get this to work.
I have my iOS app UI defined within a storyboard and the MVVM framework is mostly MVVMCross with some sprinkling of ReactiveUI thrown in for flavor.
I have a RootViewController defined where I generate the SideBarController that is attached to the AppDelegate as so:
[Register ("AppDelegate")]
public partial class AppDelegate : MvxApplicationDelegate
{
public override UIWindow Window {
get;
set;
}
public AppDelegate ()
{
}
public SidebarController SidebarController { get; set; }
public override void FinishedLaunching (UIApplication application)
{
var presenter = new MvxModalSupportTouchViewPresenter (this, Window);
var setup = new Setup (this, presenter);
setup.Initialize ();
var startUp = Mvx.Resolve<IMvxAppStart> ();
startUp.Start ();
}
}
And in the RootViewController I have:
public override void ViewDidLoad()
{
base.ViewDidLoad();
if (ViewModel == null)
return;
var appDelegate = UIApplication.SharedApplication.Delegate as AppDelegate;
appDelegate.SidebarController = new SidebarController (this,
(UIViewController)this.CreateViewControllerFor<LoginViewModel>(),
(UIViewController)this.CreateViewControllerFor<SideMenuViewModel>());
appDelegate.SidebarController.MenuWidth = 250;
appDelegate.SidebarController.ReopenOnRotate = false;
appDelegate.SidebarController.MenuLocation = SidebarController.MenuLocations.Right;
}
After the user has a successful login they are then navigated to a landing page that has a burger button on it. Once the user clicks the burger button the side menu isn't show but all tracing before and after the ToggleMenu() call gets executed. I'm racking my brain trying to get this to work but after 3 days I think I may have given myself a concussion.
Has anyone tried to get this combo working?
For me it is working. I am not exactly sure where your problems is, but this is my code:
[Register ("AppDelegate")]
public partial class AppDelegate : MvxApplicationDelegate
{
UIWindow window;
public RootViewController RootViewController { get { return window.RootViewController as RootViewController; } }
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow(UIScreen.MainScreen.Bounds);
var presenter = new Presenter(this, window);
var setup = new Setup(this, presenter);
setup.Initialize();
var startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();
window.MakeKeyAndVisible();
return true;
}
}
And for the rootcontroller:
public class RootViewController: UIViewController, IMvxCanCreateTouchView
{
public SidebarController SidebarController { get; private set; }
private UIViewController root;
public RootViewController (UIViewController root)
{
this.root = root;
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
var menuContentView = this.CreateViewControllerFor<MenuViewModel> () as MenuViewController;
SidebarController = new SidebarController (this, root, menuContentView) {
MenuLocation = SidebarController.MenuLocations.Left,
HasShadowing = false
};
}
public void NavigateToView (UIViewController view)
{
SidebarController.ChangeContentView (new UINavigationController (view));
}
}
As a Base class for my other controllers i have this:
public interface IControllerWithCustomNavigation
{
void NavigateToView (UIViewController controller);
}
public class BaseController<TViewModel>: MvxViewController where TViewModel: BaseViewModel
{
protected bool NavigationBarEnabled = true;
public new TViewModel ViewModel {
get { return (TViewModel)base.ViewModel; }
set { base.ViewModel = value; }
}
public BaseController (string nib) : base (nib, null)
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
if (NavigationBarEnabled) {
NavigationController.NavigationBarHidden = false;
updateNavigationBar ();
if (isRootViewModel()) {
addNavigationBarItemForMenu ();
}
} else if (NavigationController != null) {
NavigationController.NavigationBarHidden = true;
}
}
private void updateNavigationBar()
{
var navigationBar = NavigationController.NavigationBar;
var colorTint = UIColor.FromRGB (133, 231, 110);
var colorWhite = UIColor.White;
navigationBar.BarTintColor = colorWhite;
navigationBar.TintColor = colorTint;
navigationBar.SetTitleTextAttributes (new UITextAttributes {
TextColor = UIColor.FromRGB (13, 19, 26)
});
}
private bool isRootViewModel()
{
return NavigationController.ViewControllers.Length < 2; // Every view, even the RootView, is counted here.
}
private void addNavigationBarItemForMenu()
{
var sidebarButton = new UIBarButtonItem (
UIImage.FromFile ("menu_icon.png"),
UIBarButtonItemStyle.Plain,
(object sender, EventArgs e) => {
(UIApplication.SharedApplication.Delegate as AppDelegate).RootViewController.SidebarController.ToggleMenu();
}
);
NavigationItem.SetLeftBarButtonItem (sidebarButton, true);
}
public virtual void NavigateToView (UIViewController controller)
{
(UIApplication.SharedApplication.Delegate as AppDelegate).RootViewController.NavigateToView (controller);
}
}
So after looking over the code that Martijn posted and then actually doing some snooping through his previous posts, I decided that it would be best to create my own MvxViewPresenter and so far it works.
public class SideBarControllerTouchViewPresenter : MvxModalSupportTouchViewPresenter
{
private UIWindow _window;
public SidebarController SidebarController {
get ;
set ;
}
public UIViewController RootController {
get;
private set;
}
public SideBarControllerTouchViewPresenter (UIApplicationDelegate applicationDelegate, UIWindow window)
: base(applicationDelegate, window)
{
_window = window;
}
public override void ChangePresentation (Cirrious.MvvmCross.ViewModels.MvxPresentationHint hint)
{
base.ChangePresentation (hint);
}
protected override void ShowFirstView (UIViewController viewController)
{
base.ShowFirstView (viewController);
}
protected override UINavigationController CreateNavigationController (UIViewController viewController)
{
var navController = new UINavigationController (viewController);
var menuController = UIStoryboard.FromName ("storyboard", null).InstantiateViewController ("MenuTableViewController") as MenuTableViewController;
RootController = new UIViewController ();
SidebarController = new SidebarController (this.RootController, navController, menuController);
return navController;
}
protected override void SetWindowRootViewController (UIViewController controller)
{
_window.AddSubview (RootController.View);
_window.RootViewController = RootController;
}
}
So thanks for getting me the rest of the way there.

MvvmLight IDataService with async await

I'm trying to find a clean way to accomplish MvvmLight's IDataService pattern with async/await.
Originally I was using the callback Action method to work similar to the template's but that doesn't update the UI either.
public interface IDataService
{
void GetData(Action<DataItem, Exception> callback);
void GetLocationAsync(Action<Geoposition, Exception> callback);
}
public class DataService : IDataService
{
public void GetData(Action<DataItem, Exception> callback)
{
// Use this to connect to the actual data service
var item = new DataItem("Location App");
callback(item, null);
}
public async void GetLocationAsync(Action<Geoposition, Exception> callback)
{
Windows.Devices.Geolocation.Geolocator locator = new Windows.Devices.Geolocation.Geolocator();
var location = await locator.GetGeopositionAsync();
callback(location, null);
}
}
public class MainViewModel : ViewModelBase
{
private readonly IDataService _dataService;
private string _locationString = string.Empty;
public string LocationString
{
get
{
return _locationString;
}
set
{
if (_locationString == value)
{
return;
}
_locationString = value;
RaisePropertyChanged(LocationString);
}
}
/// <summary>
/// Initializes a new instance of the MainViewModel class.
/// </summary>
public MainViewModel(IDataService dataService)
{
_dataService = dataService;
_dataService.GetLocation(
(location, error) =>
{
LocationString = string.Format("({0}, {1})",
location.Coordinate.Latitude,
location.Coordinate.Longitude);
});
}
}
I'm trying to databind against gps coordinates but since the async fires and doesn't run on main thread it doesn't update the UI.
Might be unrelated, but AFAICT you're missing some quotes
RaisePropertyChanged(LocationString);
You pass the name of the property that changed, not its value.

Ninject, passing constructor argument to the kernel

Here is my problem:
I want to pass in one of the values to the constructor every time I request an instance form the kernel. I written some code below to illustrate the problem. The test is not failing so I guess that this works, but it does look pretty ugly. Is there a better, cleaner way to accomplish this with Ninject? Or should I rethink my design? All suggestions are appreciated.
[TestFixture]
public class Sandbox
{
[Test]
public void Run_Forrest_Run()
{
using (var kernel = new StandardKernel(new Module()))
{
var connection = new Connection(Guid.NewGuid().ToString());
var downloader = kernel.Get<IDownloader>(new IParameter[] { new Parameter("connection", connection, false) });
Assert.That(downloader.Connection.Info, Is.EqualTo(connection.Info));
}
}
public class Downloader : IDownloader
{
public Downloader(Connection connection, ILogger logger)
{
Connection = connection;
Logger = logger;
}
public Connection Connection { get; private set; }
public void Download()
{
Logger.Log("Downloading...");
}
public ILogger Logger { get; private set; }
}
public interface IDownloader
{
Connection Connection { get; }
void Download();
}
public class ConsoleLogger : ILogger
{
public void Log(string message)
{
Console.Out.WriteLine(message);
}
}
public interface ILogger
{
void Log(string message);
}
public class Connection
{
public Connection(string info)
{
Info = info;
}
public string Info { get; private set; }
}
public class Module : NinjectModule
{
public override void Load()
{
Bind<ILogger>().To<ConsoleLogger>();
Bind<IDownloader>().To<Downloader>()
.WithConstructorArgument("connection", context =>
{
var p = context.Parameters.First(x => x.Name == "connection");
return p.GetValue(context, null);
});
}
}
}
If you always want to specify the Connection when resolving a IDownloader then I think the ConstructorArgument (which is a IParameter) is what you are looking for:
[Test]
public void Run_Forrest_Run()
{
using (var kernel = new StandardKernel(new Module()))
{
var connection = new Connection(Guid.NewGuid().ToString());
var downloader = kernel.Get<IDownloader>(new [] {
new ConstructorArgument("connection", connection) });
Assert.That(downloader.Connection.Info, Is.EqualTo(connection.Info));
}
}
public class Module : NinjectModule
{
public override void Load()
{
Bind<ILogger>().To<ConsoleLogger>();
Bind<IDownloader>().To<Downloader>();
}
}

Resources