How to access RadSideDrawer from page? - nativescript

In Nativescript 5.x (TypeScript) I have successfully used the following code to access a RadSideDrawer:
import * as app from "#nativescript/core/application";
import { EventData } from "#nativescript/core/data/observable";
import { RadSideDrawer } from "nativescript-ui-sidedrawer";
export function drawerLoaded(args: EventData) {
let sideDrawer = <RadSideDrawer>args.object; <--- error
}
Now,with Nativescript 6.4 (and after migrating my app with "tns migrate") I am getting a compiler error on "tns build android":
TS2352: Conversion of type 'View' to type 'RadSideDrawer' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
I have no idea how to fix this. Could anybody tell me what i need to change? That would be super nice. Thank you!

I'm unable to reproduce the issue on my end, it may be something to do with your TS version or configurations.
An easy fix is to cast the object to unknown type as the error description suggests.
let sideDrawer = <RadSideDrawer>(<any>args.object);

Related

Compiler error screen.mainScreen is a static member of type 'Screen'

Help!. Compiler returns error
Property 'mainScreen' is a static member of type 'Screen'
i am trying to get heightDIPs but this.
You might want to check where Screen is being imported from. I've had issues in the past where VS Code would auto import the wrong Screen.
import { Screen } from '#nativescript/core';
// and the following should work
Screen.mainScreen.heightDIPs

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

Swift 2, warning: could not load any Objective-C class information from the dyld shared cache

I have found a few questions regarding this issue, yet none of them were helping with my problem. I am trying to save an object to core data using this code (which worked perfectly fine in Xcode 6 and Simulator...):
let fetchRequest = NSFetchRequest(entityName: "Patient")
let fetchedResults : [NSManagedObject]!
do {
fetchedResults = try managedContext.executeFetchRequest(fetchRequest) as! [NSManagedObject]
patienten = fetchedResults
} catch {
print("error")
}
I added the do-try-catch once I started working on this project in the Xcode 7 beta and a physical device.
Now, when I hit the Save button, this piece of code is called, the app freezes and I get the following:
warning: could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available.
Does anybody know where I went wrong?
For anyone coming across this in the future, I just ran into this problem myself and it turned out that I was actually getting a stack overflow from a recursive function.
Apparently calling setValue:forKey: on an NSObject calls the respective set[Key] function, where [Key] is the (capitalized) name you gave to the forKey section.
So, if like me, you have code that looks like the following, it will cause an infinite loop and crash.
func setName(name: String) {
self.setValue(name, forKey: "name")
}
Choose Product > Clean
I had similar issue. I deleted the app from the device. Then "Product->Clean" in the XCode menu. When I ran the app again, the issue got resolved.
Swift 3:
Actually this problem happened often when you have any property in input declared as type NSError and the compiler expect an Error output, so change the input type to Error usually solve this issue.
What helped me in similar problem (xCode 7, Swift 2):
reading this question
Or more quickly without explaining the reason of solution: just comment #objc(className) in your NSManagedObjectSubclass , that was generated from your CoreData Entity (#objc(Patient) - in your case ).
This solution (if issue still appears) does not applicable to xCode 7.1/Swift 2.1, as the way of generating NSManagedObjectSubclasses was changed.
Don't forget about cleaning your project (Product > Clean) and deleting the app from your device/simulator to replace CoreData storage on it.
let fetchRequest = NSFetchRequest(entityName: "Patient")
do {
let fetchedResults = try managedObjectContext!.executeFetchRequest(fetchRequest)
print("\(fetchedResults)")
} catch {
print("error")
}
The above code worked for me.
Maybe the issue maybe with how your core data is managed.
Check if your managedObjectContext is actually getting created.
Check the modelling of your core data

Swift Error : Use of module 'CMSampleBuffer' as a type

I saw below question to use 'captureStillImageAsynchronouslyFromConnection' function in swift:
How to convert code AVFoundation objective c to Swift?
When I try to use a AVFoundation function as following:
var stillImageOutput: AVCaptureStillImageOutput!
//...Initialize stillImageOutput
stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: {(imageSampleBuffer, error) in
if imageSampleBuffer {
var imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageSampleBuffer as CMSampleBuffer) // I get error on this line saying: 'Use of module ' CMSampleBuffer' as a type'
self.processImage(UIImage(data: imageData))
}
})
I got the error on XCode, which says 'Use of module ' CMSampleBuffer' as a type'.
I tried to rewrite that same line multiple times with slightly different ways, but I could not figure out the solution.
Am I doing something wrong or is it possibly the shaky XCode Beta not working properly?
Thank you in advance.
#Jack and #Christian's solutions worked for me.
I was not careful enough to import CoreMedia.
I never used this framework before, and did not know if the problem was due to not having imported a correct framework.
Thank you for your help!

Resources