Using an Objective C framework, which is inside a Swift framework, in a Xamarin iOS project - xamarin.ios

I have a Objective C framework. (This framework is working properly with a Swift project)
Then I have a Swift framework. This framework has used the previously mentioned Objective C framework. (This Swift framework also working in a Swift project)
Now I am trying to use that Swift framework inside a Xamarin iOS project.
I have created a Binding Library project in my Xamarin iOS project and under the Native Reference, I have added both those Swift framework and Objective C framework fat files.
I have updated the ApiDefinition file accordingly as well.
But when I run the application it launch in the phone and exit without giving any error. I'm glad if application crashed with an error. But it doesn't and I'm clueless now. Any thoughts?
Below is how I'm trying to access the methods in those frameworks inside my Xamarin iOS project
using BindingSwift;
// More codes here
public override void ViewDidLoad()
{
base.ViewDidLoad();
var myClass = new AroshaMathPerformer();
var result = myClass.DoTheMath;
Console.WriteLine("# Result = " + result);
}
But, if I add a breakpoint, it doesn't even hit at the run time before the application exits.

Assuming that everything you did is in the question, then it is expected not to work. Swift libraries are not officially supported on Xamarin.iOS. Some people made them work with these steps: https://medium.com/#Flash3001/binding-swift-libraries-xamarin-ios-ff32adbc7c76

In such a case, you can find the real reason by going to
Settings -> Privacy -> Analytics -> Analytics Data -> And find the log
file with your bundle ID and the crashed occur date/time.
The error show to me was related to #rpath/ but actually it solved after signing the bundle with a valid provisioning profile.
For those who are interesting, you can visit here to find out my experience of implementing this whole scenario mentioned in the title.

Related

How to control Adaptive Sampling in .NET Core application

I'm trying to limit the amount of data sent to Application Insights in a .NET Core program. I'm attempting to follow the documention here which says I should use the UseAdaptiveSampling method. It has the rather cryptic instruction:
Use extension methods of TelemetryProcessorChainBuilder as shown below to customize sampling behavior.
However, it doesn't tell me where exactly this extension method lives. My code is as follows:
public AppInsightsStats(string appInsightsKey)
{
TelemetryConfiguration configuration = TelemetryConfiguration.CreateDefault();
configuration.InstrumentationKey = appInsightsKey;
telemetry = new TelemetryClient(configuration);
// Enable sampling since amount of logging is massive
var builder = configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5); // <-- Compiler error here
}
However, the code doesn't compile since UseAdaptiveSampling isn't found. I have the following using statements:
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
The source code I can dig up that uses UseAdaptiveSampling all seems to be .NET Framework 4.5 code, so I'm wondering if this just isn't included with the .NET Core version. These instructions are for ASP.NET Core, but I'm wondering if they mean running that on the .NET Framework on Windows.
For console project, you should use this package Microsoft.ApplicationInsights.WorkerService. It's used for non-http application like console project.
I used your code with this package, everything is ok. Please give it a try, and let me know if you still have the issue.

Flutter For Web is there a way to store data?

I am building a web application with flutter for web, i know for sure that in the mobile version of flutter there is a way to store data in the device, but i don't know if this was even implemented in flutter for web yet.
You can use the SharedPreferences plugin for storing and retrieving persistent simple data. They gave support for the web from version 0.5.4+7
Apparently you can use localStorage: https://github.com/flutter/flutter/issues/35116
Moor is a reactive persistence data storage library which is built on top of sqlite and is based on indexedDb. This library is compatible with most of web browsers.
You can use the package and see the documentation and example from official link.
You can use local storage from dart:html package but if your app also runs on mobile it is better to use universal_html package which provide all the features of dart:html.
If your app has mobile support, dart compiler will yell at you with this at the time Im writing this answer,
Avoid using web libraries, dart:html, dart:js and dart:js_util in
Flutter packages that are not web plugins. These libraries are not
supported outside a web context; functionality that depends on them
will fail at runtime in Flutter mobile, and their use is generally
discouraged in Flutter web.
Simple example with universal_html:
import 'package:universal_html/html.dart';
void main() {
String username = window.localStorage['username'];
if (username == null) {
window.localStorage['username'] = "dartyDev";
} else {
window.localStorage.remove('username');
}
// Get the latest updated value
print(window.localStorage['username']);
}

Translated string resources in a framework are not used by the app that imports the framework in Xcode

I have a cross platform (iOS, watchOS and macOS) app. So I created a framework in Xcode and put the share files, the source code that works in all platform, into the framework.
Then I translated them. The app works fine. The only issue is that the translated string resources in the framework are never used by the app.
If I copy the content of the string resources out of the framework and insert them in to the app's string resources, it works. But I don't think it is a good idea to do things in that way.
Any idea on how to making the app use the string resources in the framework directly?
Is this on purpose or it is a bug that I should file to Apple?
Xcode 9.1 (9B55), macOS High Sierra 10.13.1 (17B48)
Swift 4.0.2
A sample project can be found here. https://www.dropbox.com/s/c6bdp28rmk9rxii/Framework%20Translation%20Issue.zip?dl=0
It turns out that NSLocalizedString in a framework must tell the bundle of the framework explicitly. Or the app that calls the framework will use main bundle to find the localization resources.
NSLocalizedString("Test", tableName: nil, bundle: bundle, comment: "Test")
You can use either init(for: AnyClass) or allFrameworks: [Bundle] with a filter to get the framework's bundle.
You must not use the id of the bundle directly, unless your are sure it is only fixed to one platform and won't be changed in future.

Xamarin iOS - Firebase Analytics is not available

I have download the example project and library from this link: Xamarin Firebase but after 2 days of configuration i get this error when i launch the app:
[Firebase/Core][I-COR000022] Firebase Analytics is not available.
I did not find documentation related to this error for Xamarin iOS Firebase Analytics and can not find a solution.
I have reference the same library of the example project, checked the GoogleService-Info.plist and insert it in the project as documentation, called the App.Configure ();.
Nothing to do, does anyone have any idea?
Resolved!
Firebase Analytics requires 3 references to work:
.Core
.Analytics
.IstanceID
Following only the code in the documentation the project at start-up load only .Core skipping the other two, this causes the error.
To work around this problem, I added in AppDelegate:
using Firebase.Analytics;
using Firebase.InstanceID;
and before of App.Configure (); i have add this two line to force the app to load the two assemblies:
Firebase.Analytics.Loader loader1 = new Firebase.Analytics.Loader();
Firebase.InstanceID.Loader loader2 = new Firebase.InstanceID.Loader();
Of course, if you implement other instructions later using these two assemblies, you will not need these two instructions.

IBM Watson Visual Recognition return empty result in Java android?

Hi i'm reading all the sources that provides help to using the service however i have this line of debug says :
I/CredentialUtils: JNDI string lookups is not available.
compile with
compile 'com.ibm.watson.developer_cloud:java-sdk:3.0.1'
VisualRecognition service = new VisualRecognition(VisualRecognition.VERSION_DATE_2016_05_19);
service.setApiKey("<api_key>");
ClassifyImagesOptions options = new ClassifyImagesOptions.Builder().images(currentSelectFileLocation).build();
VisualClassification result = service.classify(options).execute();
System.out.println(result);
the error you're getting does not come from the IBM Watson Visual Recognition Bluemix service, but from the Watson Java SDK library you're using.
see
https://github.com/watson-developer-cloud/java-sdk/search?utf8=%E2%9C%93&q=javax.naming
When you deploy some java code inside bluemix, in a liberty container, it can use JNDI to get the service credentials from inside bluemix. But when you run from outside bluemix, of course, you must provide the credentials (in your case, in your android app) in order to access the service.
It seems that for some reason your android app is importing javax.naming.Context and then the SDK is getting a little bit confusing.
You have these options here IMO
remove the javax.naming.Context from your android project
download and recompile the SDK code to fix that
Notice that providing your credentials in the android app is probably not a good idea, so I'd suggest you to take a different path here. Create a RESTful web service at Bluemix that wraps the calls to the Watson service. Of course, you may want to secure this access, because every call to the Watson service will be billed in your bluemix account.

Resources