2023年6月26日发(作者:)
⽰例汇总虽然强⼤和开放,但很多web开发者因为不熟悉原⽣API⽽难以独⽴完成。这篇帖⼦的⽬的就是汇总各种写好的NJS代码,⽅便web开发者。众⼈拾柴⽕焰⾼,有能⼒的开发者多多提交NJS代码,⼤家都会给你点赞的,我们也会为每位共享NJS代码的朋友送上200积分。Android平台Android动态权限申请监听⼿机锁屏,解锁,开屏直接拨打电话将程序切换到后台强制弹出软键盘获取安卓设备获取内存及CPU信息开启关闭蓝⽛监听蓝⽛开关状态获取蓝⽛设备列表蓝⽛连接票据打印机完整代码NFC数据读取截屏获取MAC地址获取设备当前⽹速打开⽹络设置打开各种系统设置界⾯获取WIFI列表调⽤系统控件播放视频调⽤os通讯录选择控件原⽣⽇历提醒插⼊调⽤系统控件裁剪图⽚复制内容到系统粘贴板调⽤讯飞的⽂字转语⾳功能(TTS)调⽤其它Activity后通过startActivityForResult获取返回结果接收系统⼴播消息,如监听安装卸载apk的事件判断app是否安装以监听⼿机飞⾏模式开关为例说明如何使⽤进⾏BroadcastReceiver⼴播常驻Android通知栏,不⽤个推实现本地消息推送(Local Notification)调⽤原⽣的socket连接启动⼀个原⽣service基于的⽂件系统管理功能实现打开闪光灯停⽌、开启个推推送功能var pushManager = Class("nager");
var context = eMainActivity();
function enable() {
tance().turnOnPush(context);
}
function disable() {
tance().turnOffPush(context);
}
感谢分享利⽤获取⼿机gps是否开启通过设置系统墙纸监听短信验证码限制⼿机录像时间Android监听电话呼⼊呼出Android6以上动态权限申请通知栏下载进度条打开应⽤市场iOS平台如何判断系统功能权限是否开启及提⽰⽤户开启权限获取包名var NSBundle = Class('NSBundle');
var bundle = ndle();
(Identifier());
Object(bundle);
获取设备名测试是否安装某应⽤调⽤iOS打印API通过登⼊game center设置获取内容到系统粘贴板打开页⾯默认弹出键盘播放提⽰⾳调⽤ios的⽂字转语⾳(TTS)把base64数据保存为图⽚设置webview滑动减速度var webview = tWebview();
var scrollView = tAttribute("scrollView");
tAttribute("decelerationRate:",0.99);
打开ios的Wifi设置页⾯判断是否开启消息通知检测iOS是否允许使⽤相机(感谢分享)打开应⽤市场ios获取系统的时区idvar NSTimeZone = Class("NSTimeZone");
var sys = TimeZone();
(tAttribute("name"));
状态栏显⽰⽹络请求雪花var UIApplication = ("UIApplication");
var sharedApplication = Application();
workActivityIndicatorVisible(true);
Object(sharedApplication);
获取GPS授权状态var CLLocationManager = ("CLLocationManager");
var authorizationStatus = izationStatus();
switch(authorizationStatus) {
case 0:
/// User has not yet made a choice with regards to this application
break;
case 1:
// This application is not authorized to use location services. Due
// to active restrictions on location services, the user cannot change
// this status, and may not have personally denied authorization
break;
case 2:
// User has explicitly denied authorization for this application, or
// location services are disabled in Settings.
break;
case 3:
// User has granted authorization to use their location at any time,
// including monitoring for regions, visits, or significant location changes.
break;
case 4:
// User has granted authorization to use their location only when your app
// is visible to them (it will be made visible to them if you continue to
// receive location updates while in the background). Authorization to use
// launch APIs has not been granted.
break;
case 5:
// This value is deprecated, but was equivalent to the new -Always value.
break;
defalut:
break;
}
获取⼿机存储空间var BundleClass = Class("NSBundle");
var BundleObj = ndle();
var filenamagerobj = ect("NSFileManager");
var FileAttr = (filenamagerobj,"attributesOfFileSystemForPath:error:",Path(),null);
// NSFileSystemFreeSize 参数获取剩余空间
// NSFileSystemSize 获取⼿机总存储空间
var freeSpace = (FileAttr,"objectForKey:","NSFileSystemFreeSize");
var numberFormatterObj = ect("NSNumberFormatter");
var FreeSpaceStr = (numberFormatterObj,"stringFromNumber:",freeSpace);
var freeSpace = FreeSpaceStr / 1024/1024/1024;
打开/关闭⼿机的闪光灯function turnonLight(isOn) {
if( == "iOS") {
var avcaptClass = Class("AVCaptureDevice");
if(avcaptClass) {
var device = tDeviceWithMediaType("vide"); (device, "lockForConfiguration:", null);
if(isOn) {
(device, "setTorchMode:", 1);
(device, "setFlashMode:", 1);
} else {
(device, "setTorchMode:", 0);
(device, "setFlashMode:", 0);
}
(device, "unlockForConfiguration");
}
}
};
显⽰应⽤内的ViewController// NewViewController为应⽤内创建的原⽣的ViewController类名,所调⽤页⾯的内容需要在原⽣代码中完成
var newVCobj = ect("NewViewController");
var UIApplicationClass = Class("UIApplication");
var UIAppObj = Application();
var del = (UIAppObj,"delegate");
// 如果当前应⽤delegate对象包含UIWindow对象并且变量名命名为“window”可以这么写,
// 否则需要根据实际代码情况修改
// 应⽤的delegate对象也可以添加⼀个返回UIViewController的⽅法
var appWindowObj = (del,"window");
var appRootController = (appWindowObj,"rootViewController");
(appRootController,"presentViewController:animated:completion:",newVCobj,"YES",null);
看完这些例⼦,是不是觉得JS特别强⼤?赶快拿去⽤起来吧!
发布者:admin,转转请注明出处:http://www.yc00.com/web/1687776093a43196.html
评论列表(0条)