{"id":102775,"date":"2025-03-23T09:09:42","date_gmt":"2025-03-23T04:39:42","guid":{"rendered":"https:\/\/nabfollower.com\/blog\/%d8%a2%d9%85%d9%88%d8%b2%d8%b4-%d8%a8%d8%b9%d8%af%db%8c-%d8%aa%d9%88%d8%b3%d8%b9%d9%87-hongmeng-%db%8c%da%a9-%d8%ae%d8%b7-%da%a9%d8%af-%d8%a8%d8%b1%d8%a7%db%8c-%d8%a7%d8%ac%d8%b1%d8%a7%db%8c-%d8%b0\/"},"modified":"2025-03-23T09:09:42","modified_gmt":"2025-03-23T04:39:42","slug":"%d8%a2%d9%85%d9%88%d8%b2%d8%b4-%d8%a8%d8%b9%d8%af%db%8c-%d8%aa%d9%88%d8%b3%d8%b9%d9%87-hongmeng-%db%8c%da%a9-%d8%ae%d8%b7-%da%a9%d8%af-%d8%a8%d8%b1%d8%a7%db%8c-%d8%a7%d8%ac%d8%b1%d8%a7%db%8c-%d8%b0","status":"publish","type":"post","link":"https:\/\/nabfollower.com\/blog\/%d8%a2%d9%85%d9%88%d8%b2%d8%b4-%d8%a8%d8%b9%d8%af%db%8c-%d8%aa%d9%88%d8%b3%d8%b9%d9%87-hongmeng-%db%8c%da%a9-%d8%ae%d8%b7-%da%a9%d8%af-%d8%a8%d8%b1%d8%a7%db%8c-%d8%a7%d8%ac%d8%b1%d8%a7%db%8c-%d8%b0\/","title":{"rendered":"\u0622\u0645\u0648\u0632\u0634 \u0628\u0639\u062f\u06cc \u062a\u0648\u0633\u0639\u0647 Hongmeng: \u06cc\u06a9 \u062e\u0637 \u06a9\u062f \u0628\u0631\u0627\u06cc \u0627\u062c\u0631\u0627\u06cc \u0630\u062e\u06cc\u0631\u0647 \u0633\u0627\u0632\u06cc \u062f\u0627\u062f\u0647 \u0647\u0627"},"content":{"rendered":"<p>\u062f\u0631 \u062a\u0648\u0633\u0639\u0647 Hongmeng \u060c \u0645\u062a\u062f\u0627\u0648\u0644 \u062a\u0631\u06cc\u0646 \u0631\u0648\u0634 \u0630\u062e\u06cc\u0631\u0647 \u062f\u0627\u062f\u0647 \u0647\u0627 \u062a\u0631\u062c\u06cc\u062d\u0627\u062a \u062a\u0646\u0638\u06cc\u0645\u0627\u062a \u06a9\u0627\u0631\u0628\u0631 \u0627\u0633\u062a.<\/p>\n<p>\u0628\u0627 \u0627\u06cc\u0646 \u062d\u0627\u0644 \u060c \u062a\u0631\u062c\u06cc\u062d\u0627\u062a \u06a9\u0627\u0631\u0628\u0631 \u0628\u0631\u0627\u06cc \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u062f\u0627\u062f\u0647 \u0647\u0627 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u0646\u0645\u0648\u0646\u0647 \u0645\u0634\u06a9\u0644 \u062a\u0631 \u0627\u0633\u062a.<\/p>\n<p>\u06a9\u062f \u0632\u06cc\u0631 \u062a\u0642\u0631\u06cc\u0628\u0627\u064b \u0634\u0628\u06cc\u0647 \u0628\u0647 \u0627\u06cc\u0646 \u0627\u0633\u062a:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>\ntry {\n    dataPreferences.getPreferences(getContext(this),'DB_NAME',(err, preferences) =&gt; {\n      preferences.put('name','bob',(err)=&gt;{\n        if (err) {\n          console.error(`Failed to put data. Code:${err.code}, message:${err.message}`);\n          return;\n        }\n        preferences.flush()\n        console.info('Succeeded in putting data.');\n      })\n    })\n}catch (err){\n}\n<\/code><\/pre>\n<\/div>\n<p>\u0627\u06af\u0631 \u0647\u0631 \u0628\u0627\u0631 \u06a9\u0647 \u0628\u0647 \u062f\u0627\u062f\u0647 \u0647\u0627 \u062f\u0633\u062a\u0631\u0633\u06cc \u067e\u06cc\u062f\u0627 \u0645\u06cc \u06a9\u0646\u06cc\u0645 \u060c \u0645\u062c\u0628\u0648\u0631 \u0634\u0648\u06cc\u0645 \u0686\u0646\u06cc\u0646 \u0642\u0637\u0639\u0647 \u0627\u06cc \u0627\u0632 \u06a9\u062f \u0631\u0627 \u0628\u0646\u0648\u06cc\u0633\u06cc\u0645 \u060c \u0628\u0647 \u0646\u0627\u0686\u0627\u0631 \u062e\u0631\u0627\u0628 \u062e\u0648\u0627\u0647\u06cc\u0645 \u0634\u062f \u060c \u0628\u0646\u0627\u0628\u0631\u0627\u06cc\u0646 \u0628\u0631\u0627\u06cc \u062a\u06a9\u0645\u06cc\u0644 \u062f\u0633\u062a\u0631\u0633\u06cc \u0628\u0647 \u062f\u0627\u062f\u0647 \u0647\u0627 \u0628\u0627\u06cc\u062f \u0622\u0646 \u0631\u0627 \u0645\u062d\u0635\u0648\u0631 \u06a9\u0646\u06cc\u0645 \u0648 \u06cc\u06a9 \u062e\u0637 \u06a9\u062f \u0631\u0627 \u062f\u0631 \u0628\u0631\u0646\u0627\u0645\u0647 \u0627\u062c\u0631\u0627 \u06a9\u0646\u06cc\u0645.<\/p>\n<p>\u0627\u0632 \u0622\u0646\u062c\u0627 \u06a9\u0647 \u0634\u0645\u0627 \u0628\u0627\u06cc\u062f \u0647\u0631 \u0628\u0627\u0631 \u06a9\u0647 \u0627\u0632 \u062a\u0631\u062c\u06cc\u062d\u0627\u062a \u06a9\u0627\u0631\u0628\u0631 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u06a9\u0646\u06cc\u062f \u060c \u0646\u0645\u0648\u0646\u0647 \u0627\u06cc \u0631\u0627 \u0628\u062f\u0633\u062a \u0622\u0648\u0631\u06cc\u062f \u060c \u0627\u0628\u062a\u062f\u0627 \u0631\u0648\u0634\u06cc \u0631\u0627 \u0628\u0631\u0627\u06cc \u062f\u0631\u06cc\u0627\u0641\u062a \u06cc\u06a9 \u0646\u0645\u0648\u0646\u0647 \u0628\u0646\u0648\u06cc\u0633\u06cc\u062f:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>try {\n    dataPreferences.getPreferences(getContext(this),'DB_NAME',(err, preferences) =&gt; {\n      preferences.put('name','bob',(err)=&gt;{\n        if (err) {\n          console.error(`Failed to put data. Code:${err.code}, message:${err.message}`);\n          return;\n        }\n        preferences.flush()\n        console.info('Succeeded in putting data.');\n      })\n    })\n}catch (err){\n}\n<\/code><\/pre>\n<\/div>\n<p>\u0633\u067e\u0633 \u06cc\u06a9 \u0631\u0648\u0634 \u0630\u062e\u06cc\u0631\u0647 \u0633\u0627\u0632\u06cc \u0631\u0627 \u0645\u062d\u0635\u0648\u0631 \u06a9\u0646\u06cc\u062f:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>async putData( key: string,data: string,db_name: string = defaultPreferenceName) {\n    if (!preference) {\n      await this.getPreferencesFromStorage(db_name);\n    }\n    try {\n        await preference.put(key, data);\n    } catch (err) {\n    }\n    await preference.flush();\n  }\n<\/code><\/pre>\n<\/div>\n<p>\u0631\u0648\u0634 \u062f\u0627\u062f\u0647 \u0631\u0627 \u0628\u062e\u0648\u0627\u0646\u06cc\u062f:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>async getData( key: string,db_name: string = defaultPreferenceName) {\n    if (!preference) {\n      await this.getPreferencesFromStorage(db_name);\n    }\n    return await preference.get(key, '')\n  }\n<\/code><\/pre>\n<\/div>\n<p>\u0633\u067e\u0633 \u0647\u0646\u06af\u0627\u0645\u06cc \u06a9\u0647 \u062f\u0627\u062f\u0647 \u0647\u0627 \u0628\u0627\u06cc\u062f \u062f\u0631 \u0628\u0631\u0646\u0627\u0645\u0647 \u0630\u062e\u06cc\u0631\u0647 \u0634\u0648\u0646\u062f:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>PreferenceModel.putData('name','bob')\n\n<\/code><\/pre>\n<\/div>\n<p>\u0647\u0646\u06af\u0627\u0645 \u062e\u0648\u0627\u0646\u062f\u0646 \u062f\u0627\u062f\u0647 \u0647\u0627:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>let name = await PreferenceModel.getData('name')\n\n<\/code><\/pre>\n<\/div>\n<p>\u0627\u06cc\u0646 \u062f\u0633\u062a\u0631\u0633\u06cc \u0628\u0647 \u062f\u0627\u062f\u0647 \u0647\u0627 \u0631\u0627 \u062a\u06a9\u0645\u06cc\u0644 \u0645\u06cc \u06a9\u0646\u062f \u060c \u06a9\u0647 \u0628\u0633\u06cc\u0627\u0631 \u0631\u0627\u062d\u062a \u0627\u0633\u062a.<\/p>\n<p>\u06a9\u062f \u06a9\u0627\u0645\u0644 \u0645\u062d\u0635\u0648\u0631 \u0633\u0627\u0632\u06cc \u0628\u0647 \u0634\u0631\u062d \u0632\u06cc\u0631 \u0627\u0633\u062a:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>import dataPreferences from '@ohos.data.preferences';\n\nlet context = getContext(this);\nlet preference: dataPreferences.Preferences;\nlet preferenceTemp: dataPreferences.Preferences;\nconst defaultPreferenceName: string = \"DB_NAME\"\n\nclass PreferenceModel {\n  async getPreferencesFromStorage(db_name: string) {\n    try {\n      preference = await dataPreferences.getPreferences(context, db_name);\n    } catch (err) {\n    }\n  }\n\n  \/**\n   * \u5220\u9664\n   *\/\n  async deleteLocalPreferences(key) {\n    try {\n      await dataPreferences.deletePreferences(context,key);\n    } catch(err) {\n    };\n    preference = preferenceTemp;\n  }\n\n  \/**\n   * \u5b58\u50a8\n   *\/\n  async putData( key: string,data: string,db_name: string = defaultPreferenceName) {\n    if (!preference) {\n      await this.getPreferencesFromStorage(db_name);\n    }\n    try {\n        await preference.put(key, data);\n    } catch (err) {\n    }\n    await preference.flush();\n  }\n\n  \/**\n   * \u53d6\u6570\u636e\n   *\/\n  async getData( key: string,db_name: string = defaultPreferenceName) {\n    if (!preference) {\n      await this.getPreferencesFromStorage(db_name);\n    }\n    return await preference.get(key, '')\n  }\n}\n\nexport default new PreferenceModel();\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u062f\u0631 \u062a\u0648\u0633\u0639\u0647 Hongmeng \u060c \u0645\u062a\u062f\u0627\u0648\u0644 \u062a\u0631\u06cc\u0646 \u0631\u0648\u0634 \u0630\u062e\u06cc\u0631\u0647 \u062f\u0627\u062f\u0647 \u0647\u0627 \u062a\u0631\u062c\u06cc\u062d\u0627\u062a \u062a\u0646\u0638\u06cc\u0645\u0627\u062a \u06a9\u0627\u0631\u0628\u0631 \u0627\u0633\u062a. \u0628\u0627 \u0627\u06cc\u0646 \u062d\u0627\u0644 \u060c \u062a\u0631\u062c\u06cc\u062d\u0627\u062a \u06a9\u0627\u0631\u0628\u0631 \u0628\u0631\u0627\u06cc \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u062f\u0627\u062f\u0647 \u0647\u0627 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u0646\u0645\u0648\u0646\u0647 \u0645\u0634\u06a9\u0644 \u062a\u0631 \u0627\u0633\u062a. \u06a9\u062f \u0632\u06cc\u0631 \u062a\u0642\u0631\u06cc\u0628\u0627\u064b \u0634\u0628\u06cc\u0647 \u0628\u0647 \u0627\u06cc\u0646 \u0627\u0633\u062a: try { dataPreferences.getPreferences(getContext(this),&#8217;DB_NAME&#8217;,(err, preferences) =&gt; { preferences.put(&#8216;name&#8217;,&#8217;bob&#8217;,(err)=&gt;{ if (err) { console.error(`Failed to put data. Code:${err.code}, message:${err.message}`); return; &hellip;<\/p>\n","protected":false},"author":2,"featured_media":102776,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/media2.dev.to\/dynamic\/image\/width=1000,height=500,fit=cover,gravity=auto,format=auto\/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5kbtoj67gwiqioqz6sjf.png","fifu_image_alt":"","footnotes":""},"categories":[339],"tags":[],"class_list":["post-102775","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev"],"_links":{"self":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/102775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/comments?post=102775"}],"version-history":[{"count":0,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/102775\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media\/102776"}],"wp:attachment":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media?parent=102775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/categories?post=102775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/tags?post=102775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}