我有这段代码以识别/获取设备信息。
ionic.Platform.device();
根据给出的文档Here。
deviceInformation
将返回cordova返回给它的对象。所以在cordova的对象中,对象应该包含uuid,version,model等信息。文档是Here
所以我尝试从对象undefined
获取uuid和模型,并在移动设备中构建并查看应用,然后它会在警报中显示$scope.getDeviceInfo = function() {
alert($scope.deviceInformation.uuid);
}
。
我已经证明了这一点:
type sum = 0; //replace type with int, float, double...
for(i = 1; i < p; i++) {
sum += scounts[i-1];
disp[i] = disp[0] + sum;
}
如何才能获得物体的细节,将我的cordova归还给离子?
答案 0 :(得分:4)
我也遇到了同样的问题。经过长时间的搜索,我得到了你需要的东西 - &gt;试试 - &gt;实施 - &gt;擦除 - &gt;新的试用周期。虽然我遵循了ng-cordova插件,但我知道添加ng-cordova.js不会轻易解决插件问题bcoz它只包含其网站上ng-cordova支持的插件的初始化。我已按照Here on native cordova site
给出的步骤进行操作这里要注意的是ng-cordova.js在内部调用方法和API的原生cordova,因此即使在安装ng-cordova.js之后单独安装cordova插件也非常重要。
然后我在app.module
中初始化了设备:
$ionicPlatform.ready(function() {
$scope.deviceInformation = ionic.Platform.device();
});
我在我的介绍控制器中调用了该方法:
$scope.getDeviceInfo = function() {
alert($scope.deviceInformation.uuid);
}
这给了我所需要的一切......
答案 1 :(得分:0)
您已将值分配给名为deviceInformation
的Javascript变量。因此,您无法访问AngularJs&#39; $scope.deviceInformation
。
将您的var
更改为$scope
:
ionic.Platform.ready(function() {
// will execute when device is ready, or immediately if the device is already ready.
$scope.deviceInformation = ionic.Platform.device();
$scope.currentPlatform = ionic.Platform.platform();
$scope.currentPlatformVersion = ionic.Platform.version();
$scope.getDeviceInfo = function() {
alert($scope.deviceInformation.uuid);
}
});
您也可以使用alert(deviceInformation.uuid);
,但您应该坚持使用AngularJS中的$scope
,因为它允许使用expressions与HTML进行简单绑定。
答案 2 :(得分:0)
我只需在设备就绪功能
中使用以下代码即可实现此目的 $ionicPlatform.ready(function() {
var deviceInformation = ionic.Platform.device();
console.log('platform: ' + deviceInformation.platform);
console.log('udid: ' + deviceInformation.uuid);
});
答案 3 :(得分:0)
解决方案很简单
import { BrowserModule } from '@angular/platform-browser';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { Device } from 'ionic-native';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
@NgModule({
declarations: [
],
imports: [
],
bootstrap: [IonicApp],
entryComponents: [
],
providers: [
StatusBar,
SplashScreen,
Device,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
import { Component } from '@angular/core';
import { Platform, NavController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { Device } from 'ionic-native';
import { HomePage } from '../pages/home/home';
@Component({
templateUrl: 'app.html'
})
export class MyApp{
>
rootPage:any = HomePage;
deviceName: string = '';
>
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() ={
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
});
document.addEventListener("deviceready", this.onDeviceReady, false);
}
onDeviceReady() {
console.log(Device.uuid);
console.log(Device.manufacturer);
}
}