Xamarin MvvmCross: Cannot Resolve v4.FragmentManager - xamarin

In my Xamarin Android, I want to resolve v4.fragment manager so, I'm resolving it in the following way
var ss = Mvx.Resolve<Android.Support.V4.App.FragmentManager>();
But, I'm getting error:
MvvmCross.Platform.Exceptions.MvxIoCResolveException: Failed to resolve type Android.Support.V4.App.FragmentManager
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.Resolve (System.Type t) [0x0001c] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:199
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.Resolve[T] () [0x00000] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:189
at MvvmCross.Platform.Mvx.Resolve[TService] () [0x00005] in D:\git\MvvmCross\MvvmCross\Platform\Platform\Mvx.cs:34
at TJX.Core.IoC.MvxDependencyResolver.ResolveType[T] () [0x00001] in /Users/ali00261/Loyalty-MultiBanner-Mobile/TJX.Core/IoC/MvxDependencyResolver.cs:11
Can anyone advice what am I doing wrong and how to resolve it ?
Thanks.
UPDATE
I want to replace a FrameLayout in my MvxFragment<TViewModel> with a support.v4.fragment.
ZXingScannerFragment is a support.v4.Fragment provided by 'ZXing' to scan barcode.
var scanFragment = new ZXingScannerFragment();
var ss = Mvx.Resolve<Android.Support.V4.App.FragmentManager>();
ss.BeginTransaction()
.Replace(Resource.Id.fragment_scancontainer, scanFragment)
.Commit();
My aim is to replace a view(frame layout) with a support.v4.Fragment

You can use the ChildFragmentManager to support managing Fragments inside of Fragments.
ChildFragmentManager.BeginTransaction()
.Replace(Resource.Id.fragment_scancontainer, scanFragment)
.Commit();
In terms of App.Fragment vs Support.V4.App.Fragment, it looks like you are using the wrong dependencies.
Mvvmcross offer two MvxFragment class type to match those offered in Android:
Native Fragment - which can be found in MvvmCross.Droid.FullFragging nuget package and offers MvvmCross.Droid.FullFragging.Fragments.MvxFragment. This class matches to the native Android Fragment introduced in API 11.
Support Library Fragmet - which can be found in MvvmCross.Droid.Support.V4 nuget package and offers MvvmCross.Droid.Support.V4.MvxFragment. This class matches to the Android Support Library Fragmets.
You need to use the Support Library Fragment version of MvxFragment in order to use Support.V4.App.Fragment with a ChildFragmentManager.

Related

how to get signal strength of sim network using Nativescript?

import * as application from 'application';
const TnsOneSignal = require('nativescript-onesignal').TnsOneSignal
if (application.android) {
application.on(application.launchEvent, function(args: application.ApplicationEventData) {
try {
console.log('TnsOneSignal', TnsOneSignal)
TnsOneSignal.startInit(application.android.context).init()
} catch (error) {
console.log('error', error)
}
})
}
I tried using above code and plugin but it does not work..
Can anyone help please with my code or provide better solution!
TO get the signal strength of the current mobile phone you could use the native APIs on Android and iOS and convert the code to JavaScript based on the NativeScript's marshaling rules.
For example, let's take this native solution. Here is how it would look like in NativeScript
let telephonyManager = application.android.context.getSystemService(android.content.Context.TELEPHONY_SERVICE);
let cellinfogsm = telephonyManager.getAllCellInfo().get(0);
let cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength();
cellSignalStrengthGsm.getDbm();
Of course, in Android to be able to get this information you would need an explicit permission for ACCESS_COARSE_LOCATION so you could use nativescript-permissions plugin to grant them.
Here you can find a test project demonstrating the above technique. based on the same principle you could find an iOS example and convert the code to JS using the marshaling from Objective-C to JS.

How to get isHealthDataAvailable from angular2 nativescript using api

Since that is no nativescript support with ios HealthKit..I am trying to work with the api.
To start I am trying to get a simple bool for isHealthDataAvailable():
How?
declare var NSBundle: any;
constructor() {
if (Platform.isIOS){
let healthStore = NSBundle.mainBundle.HKHealthStore();
let is_avail = healthStore.isHealthDataAvailable();
}
}
(in promise): TypeError: NSBundle.mainBundle.HKHealthStore is not a function. (In 'NSBundle.mainBundle.HKHealthStore()', 'NSBundle.mainBundle.HKHealthStore' is undefined)
This is a quote from NativeScript:
https://www.nativescript.org/blog/how-to-enable-healthkit-in-your-nativescript-application
var healthStore = HKHealthStore.new();
And this is how to use HealthKit API in NativeScript. Yes, it is THAT simple.
I beg differ...
That's not where HKHealthStore lives, please see my answer to your other question where I suggest you install the platform declarations (npm i tns-platform-declarations --save-dev). It will help you tremendously: nativescript, angular2 and heaththkit - HKHealthStore not found;
To answer this question: it should be HKHealthStore.isHealthDataAvailable() as can be seen in the screenshot below (which is a snippet of those aforementioned TypeScript declarations for iOS:
You will need to use the proper syntax for data conversion (between the Objective-C Apple API and JavaScript) as described here
e.g.
var healthStore = HKHealthStore.new();
Great detailed step by step explanation can be found in this blog post

TypeScript and d3 domain type

I have a problem, when I want to use domain.
So, I try to use next part of my code
var x = d3.time.scale()
.domain([new Date('2016-06-10'), new Date('2016-06-25')])
.rangeRound([0, 1000]);
And I get error about error types for domain...
Argument of type 'Scale' is not assignable to parameter of type 'Scale'.
Types of property 'domain' are incompatible.
Type '{ (): Date[]; (dates: number[]): Scale; (dates: Date[]): Scale; }' is not assignable to type '{ (): number[]; (values: number[]): Scale; }'.
Type 'Date[]' is not assignable to type 'number[]'.
Type 'Date' is not assignable to type 'number'.
But If we look d3 typings
domain(): Date[];
domain(dates: number[]): Scale<Range, Output>;
domain(dates: Date[]): Scale<Range, Output>;
domain can take Date array!
If we disable types, then all works fine.
And I have similar problem with another part of my code:
var drag = d3.behavior.drag()
.on('drag', function (d) {
d3.event.sourceEvent.stopPropagation();
})
.on('dragstart', function () {
//
});
I get error about:
Property 'sourceEvent' does not exist on type 'Event | BaseEvent'.
But If we look in types
export var event: Event | BaseEvent;
and
interface BaseEvent {
type: string;
sourceEvent?: Event;
}
I use typings:
"d3": "registry:dt/d3#0.0.0+20160614091820"
and awesome-typescript-loader for webpack
So, what's wrong with me?
Is your intent to use D3 v4 or D3 v3?
The code snippets you posted seem to imply D3 v3. In line with what Jake said.
There are current D3 version 4 definitions available, assuming you are using TypeScript 2.
The repo he referenced has been completely migrated to DefintitelyTyped (currently types-2.0 branch), we had mostly used it for collaborative development, while the ecosystem was still in flux...
Now to get the definitions by module simply use
npm install #types/d3-selection --save (or --save-dev if you do not publish for third party use)
As of yesterday, npm install #types/d3 --save will also get you definitions corresponding to the Standard D3 Bundle.
There was some technical debt in the publication process from DefinitelyTyped to npm #types as we did not want to break libraries that still needed the legacy D3 v3.5 definitions. This is now resolved.
Once you install the relevant definitions, you simple use TypeScript/ES6 import statements for the corresponding D3 modules (or the d3 standard bundle).
import { select, Selection } from 'd3-selection';
import * as d3Drag from 'd3-drag';
Or similar. You can also create your own TypeScript module to bundle as subset of the modules, if it makes it more convenient for you see my answer to https://stackoverflow.com/questions/40314024/typescript-d3-v4-import-not-working
Things are slightly different, if you want to use the definitions in a vanilla script with a global
If that is your use case let me know, and I can add more info.
This happened to me yesterday using Typescript 2.0 and the latest #types/d3-drag.
I think its just an issue with the typings, check here for updates: https://github.com/tomwanzek/d3-v4-definitelytyped/issues
My crud band-aid:
let drag:any = d3.behavior.drag()...

BTOUCH:error BI1017:Do not know how to make a signature for System.Int32* in method get_IssueTransport

I am binding JMC objective C static library to Xamarin compatible one, currently I am trying to build my binding project now(which contains ApiDefinition.cs, StructsAndEnums.cs and libJmcSDK.a) but when I try to build this Xamarin binding project I'm getting the following error:
BTOUCH: error BI1017: btouch: Do not know how to make a signature for System.Int32* in method 'get_IssueTransport'.
When I try to search for get_IssueTransport method, their is no search results for this, trying to find the System.Int32 signature as well but not able to find in throughout solution.
Any help in resolving this issue is much appreciated in advance. Thanks.
Answer
Remove unsafe keyword and * from int.
Like:
unsafe int*
Change int* (any pointer type) to IntPtr

Cache won't work in Appcelerator

Titanium SDK version: 1.6.
iPhone SDK version: 4.2
I am trying out the cache snippet found on the Appcelerator forum but I get an error: [ERROR] Script Error = Can't find variable: utils at cache.js (line 9).
I put this one (http://pastie.org/1541768) in a file called cache.js and implemented the code from this one (http://pastie.org/pastes/1541787) in the calling script, but I get the error.
What is wrong? I copied the code exactly.
Your problems is whilst the first pastie defines utils.httpcache. The variable utils is not defined outside of this function closure (because it is not defined anywhere in global namespace). As below shows.
(function() {
utils.httpcache = {
};
})();
To make it all work in this instance add the following code to the top of your cache.js file.
var utils = {};
This declares the utils variable in global namespace. Then when the function closure is executed below it will add utils.httpcache to the utils object.
The problem is actually not specific to Appcelerator and is just a simple JavaScript bug. Checkout Douglas Crockfords book, JavaScript the Good Parts. Reading it will literally make you a more awesome JavaScript developer.
You can't use utils.httpcache.getFromCache(url) until you add this to your code:
var utils = {};
That's because how the author created his function, it's called JavaScript module pattern and it's generally used to structure the code.
I seem to lose this value "value.httpCacheExpire = expireTime;" when the code does the "Titanium.App.Properties.setString(key,JSON.stringify(value));" so when I get it back using the getString method, there's no longer the "value.httpCacheExpire.
Anyone else have this issue? Am I missing something to get this working?

Resources