Native.js虽然强大和开放,但很多web开发者因为不熟悉原生API而难以独立完成。这篇帖子的目的就是汇总各种写好的NJS代码,方便web开发者。
众人拾柴火焰高,有能力的开发者多多提交NJS代码,大家都会给你点赞的。
见Hello H5+里Native.js部分演示及源码。
或在这里搜索“快捷方式”,http://ask.dcloud.net.cn/docs/#http://ask.dcloud.net.cn/article/88
http://ask.dcloud.net.cn/article/134
http://ask.dcloud.net.cn/question/4035
http://ask.dcloud.net.cn/question/2484
http://ask.dcloud.net.cn/question/2324
http://ask.dcloud.net.cn/question/3510
http://ask.dcloud.net.cn/question/2202
http://ask.dcloud.net.cn/question/4720
http://ask.dcloud.net.cn/article/274
http://ask.dcloud.net.cn/question/8265
http://ask.dcloud.net.cn/question/6726
http://ask.dcloud.net.cn/question/5344
http://ask.dcloud.net.cn/question/1511
http://ask.dcloud.net.cn/question/1475
http://ask.dcloud.net.cn/question/14731
http://ask.dcloud.net.cn/question/12113
http://ask.dcloud.net.cn/question/614
http://ask.dcloud.net.cn/question/5783
http://ask.dcloud.net.cn/article/215
http://ask.dcloud.net.cn/question/8314
http://ask.dcloud.net.cn/question/2034
http://ask.dcloud.net.cn/question/6473
http://ask.dcloud.net.cn/question/5783
http://ask.dcloud.net.cn/article/222
http://ask.dcloud.net.cn/question/7604
http://ask.dcloud.net.cn/question/7661
http://ask.dcloud.net.cn/question/2464
http://ask.dcloud.net.cn/question/60
http://ask.dcloud.net.cn/question/433
<span style="font-weight: normal;">var pushManager = plus.android.importClass("com.igexin.sdk.PushManager"); var context = plus.android.runtimeMainActivity(); function enable() { pushManager.getInstance().turnOnPush(context); } function disable() { pushManager.getInstance().turnOffPush(context); }</span>
感谢yeahcheung分享
http://ask.dcloud.net.cn/question/11890
http://ask.dcloud.net.cn/article/651
<span style="font-weight: normal;">var NSBundle = plus.ios.importClass('NSBundle'); var bundle = NSBundle.mainBundle(); console.log(bundle.bundleIdentifier()); plus.ios.deleteObject(bundle);</span>
http://ask.dcloud.net.cn/question/14691
http://ask.dcloud.net.cn/question/14430
http://ask.dcloud.net.cn/question/4226
见Hello H5+里Native.js部分演示及源码。
或在这里搜索“game center”,http://ask.dcloud.net.cn/docs/#http://ask.dcloud.net.cn/article/88
http://ask.dcloud.net.cn/question/3720
http://ask.dcloud.net.cn/question/2324
http://ask.dcloud.net.cn/question/3962
http://ask.dcloud.net.cn/question/4175
http://ask.dcloud.net.cn/question/6190
<span style="font-weight: normal;">var webview = plus.ios.currentWebview(); var scrollView = webview.plusGetAttribute("scrollView"); scrollView.plusSetAttribute("decelerationRate:",0.99);</span>
http://ask.dcloud.net.cn/question/7797
http://ask.dcloud.net.cn/question/4497
http://ask.dcloud.net.cn/article/188
<span style="font-weight: normal;">var NSTimeZone = plus.ios.importClass("NSTimeZone"); var sys = NSTimeZone.systemTimeZone(); console.log(sys.plusGetAttribute("name"));</span>
<span style="font-weight: normal;">var UIApplication = plus.ios.import("UIApplication"); var sharedApplication = UIApplication.sharedApplication(); sharedApplication.setNetworkActivityIndicatorVisible(true); plus.ios.deleteObject(sharedApplication);</span>
<span style="font-weight: normal;">var CLLocationManager = plus.ios.import("CLLocationManager"); var authorizationStatus = CLLocationManager.authorizationStatus(); 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; }</span>
<span style="font-weight: normal;">var BundleClass = plus.ios.importClass("NSBundle"); var BundleObj = BundleClass.mainBundle(); var filenamagerobj = plus.ios.newObject("NSFileManager"); var FileAttr = plus.ios.invoke(filenamagerobj,"attributesOfFileSystemForPath:error:",BundleObj.bundlePath(),null); // NSFileSystemFreeSize 参数获取剩余空间 // NSFileSystemSize 获取手机总存储空间 var freeSpace = plus.ios.invoke(FileAttr,"objectForKey:","NSFileSystemFreeSize"); var numberFormatterObj = plus.ios.newObject("NSNumberFormatter"); var FreeSpaceStr = plus.ios.invoke(numberFormatterObj,"stringFromNumber:",freeSpace); var freeSpace = FreeSpaceStr / 1024/1024/1024;</span>