Xamarin Embedded content contains Swift code - xamarin

I have created binding library successfully, it is initialized properly in Xamarin.iOS app, but at specific point, the app is crashing.
I tried to implement the same on XCode, it is crashing also, but the issue has been fixed by enabling the option Embedded content contains Swift Code = true as per this answer.
So How to enable same option in Xamarin?

The use of Swift frameworks and inclusion of the Swift support libs are not officially supported in the Xamarin build process and thus you have to manually bundle the relevant Swift support libraries into your Xamarin.iOS app.
Note: You have to make sure you include the correct version of those libraries.
User Flash3001 on Github has created Nugets/packages for the Swift frameworks
https://github.com/Flash3001/Xamarin.Swift3.Support
Swift 4
Libraries:
https://www.nuget.org/packages/Xamarin.Swift4.Accelerate/
https://www.nuget.org/packages/Xamarin.Swift4.ARKit/
https://www.nuget.org/packages/Xamarin.Swift4.AssetsLibrary/
https://www.nuget.org/packages/Xamarin.Swift4.AVFoundation/
https://www.nuget.org/packages/Xamarin.Swift4.CallKit/
https://www.nuget.org/packages/Xamarin.Swift4.CloudKit/
https://www.nuget.org/packages/Xamarin.Swift4.Contacts/
https://www.nuget.org/packages/Xamarin.Swift4.Core/
https://www.nuget.org/packages/Xamarin.Swift4.CoreAudio/
https://www.nuget.org/packages/Xamarin.Swift4.CoreData/
https://www.nuget.org/packages/Xamarin.Swift4.CoreFoundation/
https://www.nuget.org/packages/Xamarin.Swift4.CoreGraphics/
https://www.nuget.org/packages/Xamarin.Swift4.CoreImage/
https://www.nuget.org/packages/Xamarin.Swift4.CoreLocation/
https://www.nuget.org/packages/Xamarin.Swift4.CoreMedia/
https://www.nuget.org/packages/Xamarin.Swift4.Darwin/
https://www.nuget.org/packages/Xamarin.Swift4.Dispatch/
https://www.nuget.org/packages/Xamarin.Swift4.Foundation/
https://www.nuget.org/packages/Xamarin.Swift4.GameplayKit/
https://www.nuget.org/packages/Xamarin.Swift4.GLKit/
https://www.nuget.org/packages/Xamarin.Swift4.HomeKit/
https://www.nuget.org/packages/Xamarin.Swift4.MapKit/
https://www.nuget.org/packages/Xamarin.Swift4.MediaPlayer/
https://www.nuget.org/packages/Xamarin.Swift4.Metal/
https://www.nuget.org/packages/Xamarin.Swift4.MetalKit/
https://www.nuget.org/packages/Xamarin.Swift4.ModelIO/
https://www.nuget.org/packages/Xamarin.Swift4.Intents/
https://www.nuget.org/packages/Xamarin.Swift4.ObjectiveC/
https://www.nuget.org/packages/Xamarin.Swift4.OS/
https://www.nuget.org/packages/Xamarin.Swift4.Photos/
https://www.nuget.org/packages/Xamarin.Swift4.QuartzCore/
https://www.nuget.org/packages/Xamarin.Swift4.RemoteMirror/
https://www.nuget.org/packages/Xamarin.Swift4.SceneKit/
https://www.nuget.org/packages/Xamarin.Swift4.SIMD/
https://www.nuget.org/packages/Xamarin.Swift4.SpriteKit/
https://www.nuget.org/packages/Xamarin.Swift4.SwiftOnoneSupport/
https://www.nuget.org/packages/Xamarin.Swift4.UIKit/
https://www.nuget.org/packages/Xamarin.Swift4.Vision/
https://www.nuget.org/packages/Xamarin.Swift4.WatchKit/
https://www.nuget.org/packages/Xamarin.Swift4.XCTest/
Swift 3
https://www.nuget.org/packages/Xamarin.Swift3.AssetsLibrary/
https://www.nuget.org/packages/Xamarin.Swift3.AVFoundation/
https://www.nuget.org/packages/Xamarin.Swift3.CallKit/
https://www.nuget.org/packages/Xamarin.Swift3.CloudKit/
https://www.nuget.org/packages/Xamarin.Swift3.Contacts/
https://www.nuget.org/packages/Xamarin.Swift3.Core/
https://www.nuget.org/packages/Xamarin.Swift3.CoreAudio/
https://www.nuget.org/packages/Xamarin.Swift3.CoreData/
https://www.nuget.org/packages/Xamarin.Swift3.CoreGraphics/
https://www.nuget.org/packages/Xamarin.Swift3.CoreImage/
https://www.nuget.org/packages/Xamarin.Swift3.CoreLocation/
https://www.nuget.org/packages/Xamarin.Swift3.CoreMedia/
https://www.nuget.org/packages/Xamarin.Swift3.Darwin/
https://www.nuget.org/packages/Xamarin.Swift3.Dispatch/
https://www.nuget.org/packages/Xamarin.Swift3.Foundation/
https://www.nuget.org/packages/Xamarin.Swift3.GameplayKit/
https://www.nuget.org/packages/Xamarin.Swift3.GLKit/
https://www.nuget.org/packages/Xamarin.Swift3.HomeKit/
https://www.nuget.org/packages/Xamarin.Swift3.MapKit/
https://www.nuget.org/packages/Xamarin.Swift3.Intents/
https://www.nuget.org/packages/Xamarin.Swift3.ObjectiveC/
https://www.nuget.org/packages/Xamarin.Swift3.OS/
https://www.nuget.org/packages/Xamarin.Swift3.Photos/
https://www.nuget.org/packages/Xamarin.Swift3.QuartzCore/
https://www.nuget.org/packages/Xamarin.Swift3.RemoteMirror/
https://www.nuget.org/packages/Xamarin.Swift3.SceneKit/
https://www.nuget.org/packages/Xamarin.Swift3.SIMD/
https://www.nuget.org/packages/Xamarin.Swift3.SpriteKit/
https://www.nuget.org/packages/Xamarin.Swift3.SwiftOnoneSupport/
https://www.nuget.org/packages/Xamarin.Swift3.UIKit/
https://www.nuget.org/packages/Xamarin.Swift3.WatchKit/
https://www.nuget.org/packages/Xamarin.Swift3.XCTest/

Related

NativeScript: use custom objective-c imported class into Xcode project in NativeScript

basically I have some Objective-c class already existing and I want to use them in my NativeScript projet. Currently I have added those files to the Xcode project target and I want to be able to call my objective-c code from nativeScript js. I've read the doc but I don't understand it. It seems so complicated. basically currently all I want to do is be able to present my custom view controller by calling probably something along
const vc = MyCustomViewController.alloc.initWithNibName("xib file")
page.frame.ios.controller.present(vc,true, nil)
Am I obligated to create a plugin for that? Am I obligated to use my objective-c class to build a framework in Xcode and then import the framework?
So I found out.
Actually what you need to do is first to compile your native iOS code into a framework. As per the documentation all your classes must inherit NSObject and all your function must be marked with #objc to be exposed to the objective-c Nativescript side if you write in swift. You will notice as well that in a framework your bundle is not the main bundle. In this example you can see how you can retrieve the bundle from the framework and load a xib from it.
Then you need to add your framework file to a Nativescript plugin. For that, you want to add the framework to the plugin's iOS folder yourPlugin/platform/iOS/yourFramework.framework.
then, you need to add your plugin to your app. You can add your local plugin by using the next command line. Notice the path end with the /src folder.
tns plugin add /path/to/yourplugin/src
Now, you can then call your native functions and classes without even importing them. Of course this works only on iOS. If you run your app on android, calling those methods will crash.
To show this viewController on your Nativescript side you will need to call the following code. By the way You can find documentation elsewhere to get a reference to the current page or frame object.
const controller = page.frame.ios.controller
const vc = IOMediaViewController.create()
vc.modalPresentationStyle = UIModalPresentationFullScreen
controller.presentViewControllerAnimatedCompletion(vc,true,null)

In which package can I find Xamarin IDevice

I am writing a Xamarin Forms PCL application (both iOS and Android)
I have to pick an image from phone gallery.
I have read some documentation about this plugin:
Labs.Platform.Services.Media.MediaPicker
In my Common project, i have to put this code:
var device = Resolver.Resolve<IDevice>();
picker = DependencyService.Get<IMediaPicker>() ?? device.MediaPicker;
But I have an error on the first line: IDevice and Resolver Objects are not know. I think I am missing a reference or a using clause.
Thanks
You need to install the following Nuget package in all of your projects in the solution (i.e. PCL core project, iOS project, and the Android Project, and UWP project if using it):
https://www.nuget.org/packages/XLabs.Forms/
And you will need to add the following using statements:
using XLabs.Ioc;
using XLabs.Platform.Device;
using XLabs.Platform.Services.Media;

Issue with interacting with iPad accessory via Binding - Xamarin.iOS

I have a Barcode scanner accessory to which the iPad docks on to, hence i need to interface with the accessory to scan for barcode and use it in my application. To accomplish this, i followed the steps as enlisted here
Xamarin Hep - Link
So I went on to create a "Binding" project, added the native library i.e. ".a" file , created the APIDefinition and Structs using Sharpie and finally added the Binding project reference to my application.
In the next step, when I tried to deploy the app to iPad, encountered the error with regards to Native Linking.
In order to fix this, i mentioned the "Framework" in the LinkWith file like:
[assembly: LinkWith ("libBarCodeScannerSDK.a", SmartLink = true, ForceLoad = false, Frameworks="ExternalAccessory")]
Having done all the things stated above, I was able to deploy the app.But I am unable to make my application work with the Barcode scanner accessory. When I check the status of the scanner, its always returned as "NotConnected".
I am clueless as to how to go about debugging this issue and getting it resolved. Do appreciate, if someone can give me pointers on this.
Thanks,
Sid
most (if not all) of external accessories must set UISupportedExternalAccessoryProtocols key inside the info.plist file, see the info.plist file that the native Xcode example that came with your scanner SDK has and copy the UISupportedExternalAccessoryProtocols section to your Xamarin's app info.plist file.
Hope this helps!

How do I use the Core Plot framework with Xcode 4?

How do I install the Core Plot framework into Xcode 4?
This older tutorial has instructions on how to install it for Xcode 3, but I could not find any similar instructions for Xcode 4. What do I need to do in order to use this framework with the newer Xcode?
I made one here that followed what I did:
http://recycled-parts.blogspot.com/2011/07/setting-up-coreplot-in-xcode-4.html
Hope it helps!
It appears that I was unable to set up core plot project for the reason that I had corrupt example project which code I was using.
This are the steps:
open a project
add quartzcore framework
add other linker flags: -ObjC -all_load
add CorePlot.xcodeproj to existing project (drag and drop)
add sample class (from examples folder, drag and drop)
drag coreplot framework from added CorePlot.xcodeproj to linked frameworks
in IB
drop object and associate it to sample class
drop custom view to window and associate it vith CPTLayerHostingView
connect object and custom view
And hat is that (may sound complicated, but can be done in under a minute)
Steps can be taken in any order, except last few.
Everithing is very similar to instructions at: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application except the way it is done in xcode4 is actually easier.
Here are screenshoots that clarify the above steps: http://www.optimae.biz/data/stackoverflow/coreplot.pdf
Hope this will help someone.

Xcode 4 plugin development

I've been looking all over the place but I can't find anything. Does anyone know how to create an Xcode 4 plugin?
As far as I know there is no official way to create Xcode 4 plugins (just like there wasn't one for v3.x).
Here is an openradar on Xcode's lack of plugin support:
Please support the ability for 3rd
parties to extend Xcode via a public
plugin API. Aperture, Visual Studio,
Eclipse, TextMate and other
applications benefit from this
ability. I would like to see more
advanced refactorings, code analysis
(think Resharper by Jetbrains) and
modeling.
Provide plugin API for Xcode 4 (rdar://8622025)
Please dupe this if you want plugins!
Edit: Just stumbled upon this:
Cédric Luthi:
"Xcode 4 does support user-defined
plugins, see CLITool-InfoPlist
for an example of a working Xcode 4
plugin. You just have to add
XC4Compatible (true) in the
Info.plist."
https://github.com/0xced/CLITool-InfoPlist
That being said these GitHub repos might be handy, too:
Xcode4 Plugin-API Documentation (link dead)
Xcode Plugin Template (link updated)
Further more mogenerator's Xmod plugin might be a good starting point.
(Wasn't Xcode-4 compatible yet, last time I checked, though)
Best way to learn is to look at github plugin code (see long list below):
Basically its a plugin bundle.
No main.m No MainMenu.xib
First class loaded by setting NSPrincipalClass in info.plist
in its init: you register for AppKit notifications
See the code samples
some check the mainBundle app id to make sure this is XCode
The XCode Editor window class is DVTSourceTextView
Its a subclass of DVTSourceTextView :NSTextView : NSText
so you can register to listen for its notifications for NSTextView or NSText
such as NSTextViewWillChangeNotifyingTextViewNotification
Because its not an official standard I noticed each sample loads in different ways.
XCODE PLUGIN SAMPLES
compiled by either searching github/web for
'DVTSourceTextView'
This is the Xcode Editor window class name
or
Info-list key
'XC4Compatible'
https://github.com/omz/ColorSense-for-Xcode
https://github.com/ciaran/xcode-bracket-matcher
- uses a ruby parser run as pipe!
https://github.com/joshaber/WTFXcode
https://github.com/0xced/NoLastUpgradeCheck
http://code.google.com/p/google-toolbox-for-mac/downloads/list
see GTMXcode4Plugin
https://github.com/DeepIT/XcodeColors
https://github.com/0xced/CLITool-InfoPlist
https://github.com/sap-production/xcode-ide-maven-integration
https://github.com/ciaran/xcode-bracket-matcher
TO GET TO THE NSTextView that is the console
https://github.com/sap-production/xcode-ide-maven-integration
- (NSTextView *)findConsoleAndActivate {
Class consoleTextViewClass = objc_getClass("IDEConsoleTextView");
NSTextView *console = (NSTextView *)[self findView:consoleTextViewClass inView:NSApplication.sharedApplication.mainWindow.contentView];
if (console) {
NSWindow *window = NSApplication.sharedApplication.keyWindow;
if ([window isKindOfClass:objc_getClass("IDEWorkspaceWindow")]) {
if ([window.windowController isKindOfClass:NSClassFromString(#"IDEWorkspaceWindowController")]) {
id editorArea = [window.windowController valueForKey:#"editorArea"];
[editorArea performSelector:#selector(activateConsole:) withObject:self];
}
}
}
return console;
}
Have a look at this new plugin: https://github.com/sap-production/xcode-ide-maven-integration. Maybe you can derive some concepts for your plugin.
Yesterday ColorSense for Xcode 4 was released on Github. Since the code is really compact spread over just 3 classes, I think you should take a look over there.
Xcode does not have a public plug-in API.
This was the case with earlier versions, and is the case with Xcode 4 as well.
No, Xcode doesn't support plugins, alternatively you may try AppCode, another IDE for iOS/MacOS, it does support plugins development.

Resources