This is the 8th day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021.

UniappIOS packaging

Uniapp can be pulled up and down on every page on ios to block methods

Pages. Json Settings:

{  
    "path": "pages/helpCenter/Index",  
    "style": {  
        "app-plus": {  
        "bounce": "none"  
        }  
    }  
}
Copy the code

Uniapp real time error BUG

Problem description

When using the new Date().tolocaledateString () API in applets to retrieve the time, it is displayed as the current time in the development tool and as the time of another location in the real machine

Causes of bugs

The toLocaleDateString() method depends on the underlying operating system for formatting dates. For example, in the US, the month appears before the date (06/22/2018), while in India, the date appears before the month (22/06/2018).

The solution

Use the new Date() constructor to get the Date after Date concatenation

If no arguments are entered, the Date constructor creates a Date object based on the current time set by the system.

The difference between Date and toLocaleDateString() is that one fetches the time currently set by the system and the other formats the time by the underlying operating system

Let date = new date () date = date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate() date = date.split('/') if (date[1] < 10) { date[1] = '0' + date[1] } if (date[2] < 10) { date[2] = '0' + date[2] } date = date.join('-')Copy the code

Uniapp package Android APP file upload

Open the Android terminal, select the mobile phone file and upload it, and return to the mobile phone path:

// #ifdef APP-PLUS if (plus.os.name.toLowerCase() ! = "Android ") {uni.showModal({title: 'prompt ', content:' Support Android platform only ', success: function(res) {} }) return false } let that = this let main = plus.android.runtimeMainActivity(); let Intent = plus.android.importClass("android.content.Intent") // let fileIntent = new Intent (Intent. ACTION_GET_CONTENT) / / fileIntent setType (" image / * "); //fileIntent.setType(" audio/* "); // Select audio //fileIntent.setType(" video/* "); // FileIntent.setType (" Video /*; Image / * "); // Select both video and image fileIntent.setType("*/*"); / / no type limits fileIntent addCategory (Intent. CATEGORY_OPENABLE). The main startActivityForResult (fileIntent, OnActivityResult = function(requestCode, resultCode, data) { let Activity = plus.android.importClass("android.app.Activity") let ContentUris = plus.android.importClass("android.content.ContentUris") let Cursor = plus.android.importClass("android.database.Cursor")  let Uri = plus.android.importClass("android.net.Uri") let Build = plus.android.importClass("android.os.Build") let Environment = plus.android.importClass("android.os.Environment") let DocumentsContract = plus.android.importClass("android.provider.DocumentsContract") let MediaStore = plus.android.importClass("android.provider.MediaStore") let contentResolver = main.getContentResolver() ImportClass (contentResolver) // Return path let path = "if (resultCode == activity.result_ok) {let uri = Data.getdata () if ("file" == uri.getScheme().tolowerCase ()) {// Open path = uri.getPath() return; } if (build.version.sdk_int > build.version_codes.kitkat) {//4.4 after path = getPath(this, Uri)} else {//4.4 The following system call method path = getRealPathFromURI(uri)} // callback that.resultPath(path)} //4.4 Obtain the absolute file path from the URI function getPath(context, uri) { let isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT let scheme = uri.getScheme().toLowerCase() if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { let docId = DocumentsContract. GetDocumentId (uri) let the split = docId. Split (" : ") let type = the split is [0] / / if the internal storage if (= = "primary" type.toLowerCase()) { return Environment.getExternalStorageDirectory() + "/" + split[1] } else { return '/storage/' + type + "/" + split[1] } } // DownloadsProvider else if (isDownloadsDocument(uri)) { let id = DocumentsContract.getDocumentId(uri) let split = id.split(":") return split[1] } // MediaProvider else if (isMediaDocument(uri)) { let docId = DocumentsContract.getDocumentId(uri) let split = docId.split(":") let type = split[0] let contentUri = null if ("image" == type.toLowerCase()) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video" == type.toLowerCase()) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio" == type.toLowerCase()) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } let selection = "_id=?" let selectionArgs = [split[1]] return getDataColumn(context, contentUri, selection, selectionArgs) } } // MediaStore (and general) else if ("content" == scheme) { return getDataColumn(context, uri, null, null); } // File else if ("file" == scheme) { return uri.getPath(); }} / / 4.4 following the absolute path function getRealPathFromURI (uri) {let res = null let proj = [MediaStore. Images. Media. The DATA] let cursor = contentResolver.query(uri, proj, null, null, null); if (null ! = cursor && cursor.moveToFirst()) {; let column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); res = cursor.getString(column_index); cursor.close(); } return res; Function getDataColumn(context, URI, selection, selectionArgs) {let cursor = null; let column = "_data"; let projection = [column]; cursor = contentResolver.query(uri, projection, selection, selectionArgs, null); if (cursor ! = null && cursor.moveToFirst()) { let column_index = cursor.getColumnIndexOrThrow(column); return cursor.getString(column_index); } } function isExternalStorageDocument(uri) { return "com.android.externalstorage.documents" == uri.getAuthority() ? true : false } function isDownloadsDocument(uri) { return "com.android.providers.downloads.documents" == uri.getAuthority() ? true : false } function isMediaDocument(uri) { return "com.android.providers.media.documents" == uri.getAuthority() ? True: false}} // #endif // # ifNdef app-plus uni.showModal({title: 'prompt ', content:' Support Android platform only ', success: function(res) { } }) // #endifCopy the code

Uniapp message push function

Manually triggered push

plus.push.createMessage(msg.payload.content, url, options)
Copy the code

Description:

Create push messages locally and add them to the system message center.

Parameters:

Content: (String) Mandatory

The content displayed in the message, the text content displayed in the system notification center.

Payload: (String) Optional

The data carried by the message can be customized according to the business logic.

Options: (MessageOptions) This parameter is optional

To create additional parameters for the message, see MessageOptions.

Test push CID fetching code

To receive notifications, the phone needs to turn on notification permissions

The front end needs to pass the clientid to the back end which is the clientid

// It is recommended to pass the value to the back end when login const info = plus.push.getClientInfo() const CID = info.clientidCopy the code

Uniapp picture upload

<template> <view class="context"> <view v-for="(item,index) in items" :key="index"> <view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30"> <view class="u-m-r-10" @click="ChooseImage(item)"> <u-avatar :src="src" size="140"></u-avatar> </view> </view> </view> </view> </view> </template> <script> export default { data() { return { src: '', item: '', items: [], personID: '' } }, onLoad() { this.getHome() }, methods: GetHome (item) {const that = this uni. GetStorage ({key: 'personID', success: Function (res) {const id = res.data uni.request({url: 'HTTP: ', // method: 'get', success: (res) = > {that. The items = res. The data that the SRC = ` http://113.142.69.131:12580${res. Data [0]. ImageUrl} `}}}}})), ChooseImage(item) {let self = this; Uni. ChooseImage ({count: 1, //1 sizeType: ['original', 'compressed'], // select sourceType: ['album'], // Select success from album: (res) => {const tempFilePaths = res.tempfilepaths; console.log(tempFilePaths[0]) const uploadTask = uni.uploadFile({ url: '', filePath: tempFilePaths[0], name: 'file', success: function(res) { let reg = /\\/g; let replaceAfter = res.data.replace(reg,''); let imageUrl = res.data.slice(26, -3) self.bindWare(imageUrl) } }) } }) }, BindWare (url) {console.log(url) const that = this const id = that.items[0].id that.items[0].imageurl = url console.log(that.items) uni.request({ url: ``, method: 'PUT', data: that.items[0], success: (res) => { that.getHome() } }) } } }; </script>Copy the code