Quantcast
Channel: Xamarin.Mac — Xamarin Community Forums
Viewing all 1367 articles
Browse latest View live

An example of using MPV to Play video on macOS

$
0
0

MPVDemo-macOS

This is a Xamarin macOS Project to example how to Use MPV to play video.

You should find all the reference links from github.com/kevinzhow/MPVDemo-macOS since I can not post Links.

Basic flow

  1. Finding MPV dylibs
  2. Using DllImport to bind dylibs
  3. Play video

Finding MPV Dylibs

The most easiest way is grabbing it from my project and all these libs were modified from
IINA project.

IINA's original dylibs were using @rpath to solve the Search Path which will cause System.DllNotFoundException.

You can fix it by install_name_tool

Quick Example:

otool -L libavfilter.6.dylib

install_name_tool -change @rpath/libavutil.55.dylib  @loader_path/libavutil.55.dylib  libavfilter.6.dylib

DllImport

DllImport is C# way to do dlopen.

You can find the instruction from Xamarin Website.

Quick Example:
c# [DllImport("libmpv.1.25.0.dylib", EntryPoint = "mpv_create")] private static extern IntPtr MpvCreate();


WebApp.Start throws "Access Denied" socket exception

$
0
0

I wrote a small self-hosted (terminal) OWIN app that used to work a few weeks back. The problem now (I assume after upping to High Sierra) is that I can no longer bind to the local IP addresses. When I call WebApp.Start<...>({address}) I get a TargetInvocationException with an inner SocketException with an "Access Denied" message and error code of 10013.

I have tried running Visual Studio under root privileges but I get the same result.

What do I need to do to be able to bind to the local addresses of my Mac?

Stable Channel: Xamarin.Mac 4.0.0.215, 15.5.3 Servicing Release

Sharing Example of how to use MPV to play video on macOS project

$
0
0

MPVDemo-macOS

This is a Xamarin macOS Project to example how to Use MPV github.com/mpv-player/mpv to play video.

Basic flow

  1. Finding MPV dylibs
  2. Using DllImport to bind dylibs
  3. Play video

Finding MPV Dylibs

The most easiest way is grabbing it from github.com/kevinzhow/MPVDemo-macOS/tree/master/MPVDemo/libs and all these libs were modified from
IINA github.com/lhc70000/iina/tree/develop/deps/lib project.

IINA's original dylibs were using @rpath to solve the Search Path which will causing System.DllNotFoundException.

You can fix it by install_name_tool thanks to brendanzagaeski brendanzagaeski.appspot.com/xamarin/0004.html.

Quick Example:

otool -L libavfilter.6.dylib

install_name_tool -change @rpath/libavutil.55.dylib  @loader_path/libavutil.55.dylib  libavfilter.6.dylib

DllImport

DllImport is C# way to do dlopen developer.xamarin.com/api/type/MonoTouch.ObjCRuntime.Dlfcn/

You can find the instruction from Xamarin Website developer.xamarin.com/guides/ios/advanced_topics/native_interop/#Accessing_C_Dylibs.

Quick Example:
```c#
[DllImport("libmpv.1.25.0.dylib", EntryPoint = "mpv_create")]
private static extern IntPtr MpvCreate();

<br />##Play

MPV has made a great example of how to interaction mpv with C# at mpv-exmaples github.com/mpv-player/mpv-examples/blob/master/libmpv/csharp/Form1.cs

Cocoa platform's specific can also be found at cocoa-example github.com/mpv-player/mpv-examples/tree/master/libmpv/cocoa

```c#
var windowId = VideoView.Handle.ToInt64();

MpvInitialize(_mpvHandle);

DoMpvCommand("loadfile", _mediaFilePath);

Play();

issues with RestoreCompletedTransactions and Mac OS 12.13.XX ?

$
0
0

We are using RestoreCompletedTransactions to replay the transactions and this worked fine up Mac OS 12.13.??

SKPaymentQueue.DefaultQueue.RestoreCompletedTransactions();

Now we are finding RestoreCompletedTransactions does not request authentication or do anything , but buying still works fine ?

Any thoughts ?

Unable to resolve Native Bindings MAC

$
0
0

Hi Chris,
We have a .a file that we recived from Third party but they only have the native libraries written in objective C. I need to use them in Xamarin.MAC project. My Bindings project does not throw any errors but my Xamarin.MAC project does Undefined symbols for architecture x86_64:
"_AudioObjectGetPropertyData", referenced from:
-[CocoaAudioUnitSource startInternalWithBuffer:] in Cocoa.a

I don't understand this I looked up to each .a file and see architecture is x86_64. Can you please give me some links with info on how to tackle this?

Thanks!

Xamarin Mac KVO model bindings - change fires twice

$
0
0

I am trying to implement KVO bindings in a Xamarin Mac desktop app.
I have followed the docs, and it is working, but the bindings appear to trigger 2 change events each time!

If I create a KVO model with a binding like this...

    private int _MyVal;
    [Export("MyVal")]
    public int MyVal
    {
        get { return _MyVal; }
        set
        {
            WillChangeValue("MyVal");
            this._MyVal = value;
            DidChangeValue("MyVal");
        }
    }

And bind a control to it in Xcode under the bindings section with the path self.SettingsModel.MyValue

It all appears to work fine, the control shows the model value, changing the model value programmatically updates the control and changing the control updates the model value.

However, it runs the change event twice.

I am listening to the change so I can then hit an API with the value.

SettingsModel.AddObserver(this, (NSString)key, NSKeyValueObservingOptions.New, this.Handle);

Then later...

 public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
    {
        switch (keyPath)
        {
            case "MyValue":

            // CODE HERE THAT UPDATES AN API WITH THE VALUE
            // But this handler fires twice.


            break;
        }
    }

Im not sure if its Xamarin or XCode that is causing the double trigger.

Interestingly, if you don't specify the Xcode WillChangeValue and DidChangeValue methods, then it doesn't trigger twice - as though Xamarin has automatically triggered the change once. However, it no longer triggers a change when programmatically updating the model value...

[Export("MyVal")]
public int MyVal { get; set }

The above will work for the Xcode controls, they will update the model and trigger a change event.

But programmatically updating it

this.SettingsModel.MyVal = 1;

Does not trigger the change event.

It's very confusing, any idea on how to stop 2 change events firing, as I don't want to hit the API twice every time!

When it fires twice, the stack trace (abridged) for the first has...

MainViewController.ObserveValue
ObjCRuntime.Messaging.void_objc_msgSendSuper_IntPtr()
Foundation.NSObject.DidChangeValue(string forKey)
CameraSettingsModel.set_MyValue(int value)
AppKit.NSApplication.NSApplicationMain()
AppKit.NSApplication.Main(string[] args)
MainClass.Main(string[] args)

Which looks fine, but the second...

MainViewController.ObserveValue
AppKit.NSApplication.NSApplicationMain()
AppKit.NSApplication.Main(string[] args)
MainClass.Main(string[] args)

Has no mention of the Setting Model triggering the event

Unhandled Exception: System.TypeInitializationException: System.Drawing.GDIPlus

$
0
0

I'm using xfinium library (http://www.xfiniumpdf.com/) to generate pdf in my app. Everything works fine in debug mode, but in release mode code fails with the exception

 Unhandled Exception:
    System.TypeInitializationException: The type initializer for 'System.Drawing.GDIPlus' threw an exception. ---> System.DllNotFoundException: gdiplus
      at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
      at System.Drawing.GDIPlus..cctor () [0x000b0] in <cc5085378d934997a7b811d65661a6ac>:0
       --- End of inner exception stack trace ---
      at System.Drawing.Bitmap..ctor (System.String filename, System.Boolean useIcm) [0x00022] in <cc5085378d934997a7b811d65661a6ac>:0
      at System.Drawing.Bitmap..ctor (System.String filename) [0x00000] in <cc5085378d934997a7b811d65661a6ac>:0
      at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:.ctor (string)
      at Xfinium.Pdf.Graphics.PdfImage..ctor (System.String fileName, System.Int32 frame) [0x00006] in <6d56863068554f42b6db33640603cec4>:0
      at Xfinium.Pdf.Graphics.PdfImage..ctor (System.String fileName) [0x00000] in <6d56863068554f42b6db<…>

Here is my release configuration options

Target Framework: Xamarin.Mac Full


App launch via Custom URL scheme

$
0
0

I have a very simple app, which need to be started from a webbrowser via a registered URI-scheme.
Everything went fine when the app is running. But when the app is not running, and it's called from a browser, the app is launched, but the handleGetURLEvent:withReplyEvent: method isn't get fired.

Is there an option to debug this scenario, so that the app is launched with a URI?

public override void DidFinishLaunching(NSNotification notification)
        {
           NSAppleEventManager appleEventManager = NSAppleEventManager.SharedAppleEventManager;
            appleEventManager.SetEventHandler(this, new Selector("handleGetURLEvent:withReplyEvent:"), AEEventClass.Internet, AEEventID.GetUrl);

            base.DidFinishLaunching(notification);
        }

    [Export("handleGetURLEvent:withReplyEvent:")]
            private void HandleGetURLEvent(NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvent)
            {
                // Received event is a list (1-based) of URL strings
                for (int i = 1; i <= evt.NumberOfItems; i++)
                {
                    var innerDesc = evt.DescriptorAtIndex(i);

                    if (!string.IsNullOrEmpty(innerDesc.StringValue))
                    {
                        app.HandleIncommingData(new Uri(innerDesc.StringValue));
                    }
                }
            }

Release Build won't load after installation

$
0
0

I have created an installation package and installed my application to my mac but the application won't load. The release build will run from visual studio but not when installed. There are no errors when creating installation package. I am unsure why the application won't load to what to check.

Does MvvmCross Dependency Injection work on Xamarin Mac ? I get NullException on registering

$
0
0

I'm trying to use MVVMCross DI on Mac. I created a new Cocoa project and added the MVVMCross package, then changed my Main.cs to this most simple example, but I get a NullException on RegisterSingleton.

using System.Diagnostics;
using AppKit;
using MvvmCross.Platform;

namespace TestMac
{

    public interface ISomething {
    }

    public class Something : ISomething {
    }

    static class MainClass
    {
        static void Main(string[] args)
        {
            Mvx.RegisterSingleton<ISomething>(new Something());
            var s = Mvx.Resolve<ISomething>();
            Debug.WriteLine("done");

            NSApplication.Init();
            NSApplication.Main(args);
        }
    }
}



Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at MvvmCross.Platform.Mvx.RegisterSingleton[TInterface] (TInterface service) [0x00006] in <6adc0d5857264558a9d45778a78ae02a>:0
  at TestMac.MainClass.Main (System.String[] args) [0x00001] in /Users/gary/temp/TestMac/TestMac/Main.cs:18
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at MvvmCross.Platform.Mvx.RegisterSingleton[TInterface] (TInterface service) [0x00006] in <6adc0d5857264558a9d45778a78ae02a>:0
  at TestMac.MainClass.Main (System.String[] args) [0x00001] in /Users/gary/temp/TestMac/TestMac/Main.cs:18

creating build for multiple project under single solution in visual studio mac

$
0
0

hi,

i am creating mac os application. i have 5 different .app created for different purpose, now i want it to be deployed on any machine as a single .app and i have business login in my project and they all have to refer the same dll. how to implement shared dll concept in visual studio for mac and share the mono bundle among all the other project since my .app size is getting bigger just because each .app is having the same mono bundle copied in different places. kindly help me as soon as possible

Has anyone used PCLCrypto with Xamarin.Mac? -- Getting NotImplementedException

$
0
0

Has anyone used PCLCrypto with Xamarin.Mac?
I am getting NotImplementedException when I call any of the methods.
Is there any restriction on using PCL in Xamarin.Mac?

using PCLCrypto;
using PCLCrypto.WinRTCrypto;

var mac = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithm.HmacSha1);

Unhandled Exception:
System.NotImplementedException: Not implemented in reference assembly.
at PCLCrypto.WinRTCrypto.get_MacAlgorithmProvider () [0x00000] in :0

--
https://github.com/AArnott/PCLCrypto

How to properly map a DLL name to a native Mac framework

$
0
0

I am trying to use the Chromium Embedded Framework.framework in my Mac app. In my sample .net code, this framework is referenced as libcef.dll. When I call a method on the framework, I get a System.DllNotFound exception. I have looked at DLL maps to map the CEF framework to the expected DLL name and I have the following map but this did not resolve the issue.

<configuration>
       <dllmap dll="libcef" target="/Library/Frameworks/Chromium\ Embedded\ Framework.framework/Chromium Embedded Framework" />
</configuration>

I have also added the framework to my project as a native reference but nor did this resolve the issue.

Does anyone know how I might be able to get around this DllNotFound exception?

The stack trace is this.

System.DllNotFoundException: libcef
at at (wrapper managed-to-native) Xilium.CefGlue.Interop.libcef:api_hash (int)
at Xilium.CefGlue.CefRuntime.CheckVersionByApiHash () [0x00002] in /Users/jlaase/Documents/dev/xilium.cefglue/CefGlue/CefRuntime.cs:106
at Xilium.CefGlue.CefRuntime.CheckVersion () [0x00002] in /Users/jlaase/Documents/dev/xilium.cefglue/CefGlue/CefRuntime.cs:92
at Xilium.CefGlue.CefRuntime.Load () [0x0000c] in /Users/jlaase/Documents/dev/xilium.cefglue/CefGlue/CefRuntime.cs:81
at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2879
at System.Threading.Tasks.Task.Execute () [0x00010] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2502
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113
at Demo.CefGlue.AppDelegate+c__async0.MoveNext () [0x00099] in <6839508fd4284d13b86c5e47bd563ec6>:0
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state) [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018
at MonoMac.AppKit.AppKitSynchronizationContext+c__AnonStorey0.<>m__0 () [0x00000] in <69849e6b886848f68ef0f56b62fe76aa>:0
at MonoMac.Foundation.NSAsyncActionDispatcher.Apply () [0x00002] in <69849e6b886848f68ef0f56b62fe76aa>:0
at at (wrapper managed-to-native) MonoMac.AppKit.NSApplication:NSApplicationMain (int,string[])
at MonoMac.AppKit.NSApplication.Main (System.String[] args) [0x0003d] in <69849e6b886848f68ef0f56b62fe76aa>:0
at Demo.CefGlue.MainClass.Main (System.String[] args) [0x00006] in <6839508fd4284d13b86c5e47bd563ec6>:0

Thanks,

Josh

Followed sandbox directions, but app still doesn't run as sandboxed

$
0
0

We're looking to get our mature Xamarin Mac application published on the app store, so I've started down the path of finding out what needs to be changed to enable this to happen, and the first step is to attempt to get the app running in 'sandboxed' mode. I've followed this procedure here to the letter:
https://developer.xamarin.com/guides/mac/application_fundamentals/sandboxing/
... but the app still is NOT running as 'sandboxed' (according to Activity Monitor), and it's operation definitely seems normal (i.e. it isn't causing exceptions or problems that I would expect it to cause due to the way we use some local files etc).

One question I have is that in the "Enable the app sandbox" step it instructs "Check both Enable Entitlements and Enable App Sandboxing", however I can't see any "Enable Entitlements" checkbox or option. Is that what I'm missing?

OS and app info:
macOS 10.13.3
VS Community 7.3.3 (build 5)
Xamarin Mac 4.0.0.215
Xcode 9.2 (13772)

Any suggestions as how to work out what the problem is?

Thanks

Mike


Stable Channel: Xamarin.Mac 4.0.0.216, 15.5.5 Servicing Release

Create pkg from visual studio for windows?

$
0
0
Currently I'm having an iOS, Andoid and WPF applications.

I use a Windows machine that is connected to a Mac to build their artifacts (ipa,apk,exe).

When I add a Mac application to the build, without checking the option to create a package, the build passes. Otherwise it fails with a compilation error.

If I can build the Mac application from a Windows device successfully, why can't I create a package as well? Is it a local bug or not yet supported? Will it be supported if so and when?

Thanks.

Sandboxing continued - no way around use of NSDocument to gain read/write access to files?

$
0
0

I just wanted to check this aspect before proceeding with a bunch of code changes. There is this quote in the Sandboxing documents:
"Opening, Saving and Tracking Documents - If you are managing documents using any technology other than NSDocument, you should switch to it because of the built in support for the App Sandbox. NSDocument automatically works with PowerBox and provides support for keeping documents within your sandbox if the user moves them in Finder."

Currently we aren't using NSDocument, but rather are doing 'manual' handling of the particular files our application loads from and saves to (i.e. using File.ReadAllBytes, calling FSOpenSavePanelDelegate etc). I've found that I get an 'unauthorized access exception' in my sandboxed app, even with the "User Selected File" entitlement set to "Read/WriteAccess", when trying to open our files from the user's 'Document' directory. I am guessing this is happening precisely because of us not using NSDocument, and that there isn't any way around rewriting things to use NSDocument, is that correct?

Thanks

Mike

Developer ID Code Signing + Provisioning Profiles not Working (Xamarin.Mac + Code Signing + VS 7.4)

$
0
0

Hi Xamarin,
I'm running into issues where I'm not able to build my project because Xamarin.Mac is not able to find an applicable Provisioning Profile. This worked without issue prior to upgrading to VS7.4.
Here's a screen shot showing that I want to use Developer ID signing (for non-appstore distribution):

Here is the provisioning profile set up on Developer.Apple.com:

And here is a screen shot showing that it is installed:

And here is a screen shot showing the error I get when I try to build:

Am I missing something or is this a VS bug?

CoreWLAN Wifi Password/Passphrase in Xamarin.Mac

$
0
0

It seems that classes such as CWWirelessProfile and CW8021XProfile have been removed from the CoreWLAN namespace leaving just a CWNetworkProfile. But unlike the the 2 deprecated classes, CWNetworkProfile does not have a Password nor a Passphrase property.

Does anybody know how I can programmatically retrieve the Wifi password/passphrase for a CWNetworkProfile?

Thanks

Here's my current environment...

=== Visual Studio Community 2017 for Mac ===

Version 7.3.3 (build 7)
Installation UUID: 52841cf1-dbf0-469c-a714-a263f1d0573b
Runtime:
Mono 5.4.1.7 (2017-06/e66d9abbb27) (64-bit)
GTK+ 2.24.23 (Raleigh theme)

Package version: 504010007

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Version: 2.0.0
SDK: /usr/local/share/dotnet/sdk/2.0.0/Sdks
SDK Version: 2.0.0
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version: 8.1.5.0 (Visual Studio Community)
Android SDK: /Users/allan/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
6.0 (API level 23)
7.1 (API level 25)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 26.0.0
SDK Build Tools Version: 25.0.3

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Apple Developer Tools ===

Xcode 9.2 (13772)
Build 9C40b

=== Xamarin.Mac ===

Version: 4.0.0.216 (Visual Studio Community)

=== Xamarin Inspector ===

Not Installed

=== Xamarin.iOS ===

Version: 11.6.1.4 (Visual Studio Community)
Hash: db807ec9
Branch: xcode9.2
Build date: 2018-01-10 16:45:48-0500

=== Build Information ===

Release ID: 703030007
Git revision: 125911fb4accc4309b2cee5c81c970c7cff9b0e0
Build date: 2018-01-22 17:46:46-05
Xamarin addins: 463e21a6d9d4f6b57f923df376fff093a1dd9404
Build lane: monodevelop-lion-d15-5

=== Operating System ===

Mac OS X 10.12.6
Darwin 16.7.0 Darwin Kernel Version 16.7.0
Thu Jan 11 22:59:40 PST 2018
root:xnu-3789.73.8~1/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Internet of Things (IoT) development (Preview) 7.1

Viewing all 1367 articles
Browse latest View live