##Andriod封装
#建立目录
cordova create cfjrAndroid
#添加platform
cd cfjrAndroid
cordova platform add android
#添加插件
cordova plugin add cordova-plugin-crosswalk-webview
cordova plugin rm cordova-plugin-crosswalk-webview
cordova plugin add cordova-plugin-inappbrowser
cordova plugin add cordova-plugin-device-orientation
cordova plugin add cordova-plugin-screen-orientation
cordova plugin add cordova-plugin-x-socialsharing
cordova prepare
cordova plugin add cordova-plugin-device
cordova plugin add cordova-plugin-app-version
cordova plugin add cordova-plugin-file-transfer
cordova plugin add cordova-plugin-camera
cordova plugin add cordova-plugin-splashscreen
#待测试
cordova plugin add cordova-plugin-whitelist
#编译
cordova build android
#文件index.html
======================================================================
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="telephone=no" name="format-detection">
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta content=
"user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi"
name="viewport">
<script src="cordova.js" type="text/javascript"></script>
<script src="js/index.js" type="text/javascript"></script>
<title>Camera Cordova Plugin</title>
</head>
<body>
<button>Capture Photo</button><br>
<button>From Photo
Library</button><br>
<img id="image" src="" style="display:none;width:100%;">
<button>Upload</button>
</body>
</html>
======================================================================
#文件index.js
======================================================================
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
}
// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageURI) {
alert("fire");
// Uncomment to view the base64-encoded image data
console.log(imageURI);
// Get image handle
//
var cameraImage = document.getElementById('image');
// Unhide image elements
//
cameraImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
//
cameraImage.src = imageURI;
}
// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
alert("fire");
// Uncomment to view the image file URI
console.log(imageURI);
// Get image handle
//
var galleryImage = document.getElementById('image');
// Unhide image elements
//
galleryImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
//
galleryImage.src = imageURI;
}
// A button will call this function
//
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality: 30,
targetWidth: 600,
targetHeight: 600,
destinationType: destinationType.FILE_URI,
saveToPhotoAlbum: true
});
}
// A button will call this function
//
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, {
quality: 30,
targetWidth: 600,
targetHeight: 600,
destinationType: destinationType.FILE_URI,
sourceType: source
});
}
// Called if something bad happens.
//
function onFail(message) {
//alert('Failed because: ' + message);
}
function upload() {
var img = document.getElementById('image');
var imageURI = img.src;
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
var params = new Object();
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "http://cfjr.ddxiami.com/upload.php", win, fail,
options);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
======================================================================
#APP图标
#启动画面
http://www.cnblogs.com/a420120206/p/5856371.html
http://blog.csdn.net/bobo8945510/article/details/52883751
#IOS顶部覆盖问题
http://blog.csdn.net/alex8046/article/details/43835851
======================================================================
#pragma mark View lifecycle
- (void)viewWillAppear:(BOOL)animated
{
// View defaults to full size. If you want to customize the view's size, or its subviews (e.g. webView),
// you can do so here.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
CGRect viewBounds = [self.webView bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20;
self.webView.frame = viewBounds;
}
[super viewWillAppear:animated];
}
======================================================================
#IOS打包过程
http://www.jianshu.com/p/6e228ce32ccd
https://www.pgyer.com/cfjrtestios
pre.im和蒲公英
|