DEV Community

Cover image for [Learn HarmonyOS Next Knowledge Daily] Debugging, Network, Caching, Rich Text Editing, etc.
kouwei qing
kouwei qing

Posted on

[Learn HarmonyOS Next Knowledge Daily] Debugging, Network, Caching, Rich Text Editing, etc.

[Learn HarmonyOS Next Knowledge Daily] Debugging, Network, Caching, Rich Text Editing, etc.

1. How to Use a Release Certificate for Debugging?

Since some functions require certificate information verification, debugging needs to be performed using both a debug certificate and a release certificate. However, after using the release certificate, an installation error occurs:

05/14 19:04:39: Install Failed: error: failed to install bundle.code:9568322error: signature verification failed due to not trusted app source.View detailed instructions.$ hdc shell rm -rf data/local/tmp/c07053e4cafe4f06bbbfecc3c2a697bbError while Deploy Hap.

Specification Issue: Release certificates published on the AppGallery cannot be installed through non-AppGallery channels.

Solution: For testing release certificate applications, consider using AGC->Open Testing.

2. Is netBearType Defined as an Array Type in the Documentation the Current Specification?

In scenarios where both Wi-Fi and cellular networks are connected (dual-mode), the netBearType parameter only returns the status information of Wi-Fi. The array type definition is the current specification to handle multiple calling scenarios.

3. How to Make RichEditor and a Component a Whole for Adaptive Scrolling Based on Cursor Position?

There is a Component above RichEditor, and the goal is to make RichEditor and the Component a whole that can scroll adaptively based on the cursor position. Currently, using a Scroller cannot obtain the specific coordinates of the cursor in RichEditor (cursor x and y positions relative to RichEditor), making scrolling impossible.

Solution: Wrap RichEditor and the Component with a Scroll component. Use the onAreaChange callback to call scroller.scrollBy to adjust the height of the scrolling component.

Reference Code:

@Entry
@Component
struct Index {
  editorController = new RichEditorController()
  scroller: Scroller = new Scroller()

  build() {
    Column() {
      Scroll(this.scroller) {
        Column() {
          Image($r('app.media.startIcon'))
            .width('100%')
            .height(200)
            .margin({ bottom: 20 })
          RichEditor({ controller: this.editorController })
            .id('RichEditor')
            .width('100%')
            .backgroundColor(Color.Yellow)
            .onReady(() => {
              this.editorController.addImageSpan($r("app.media.startIcon"),
                {
                  imageStyle:
                  {
                    size: ["100px", "100px"]
                  }
                })
              this.editorController.addTextSpan('男生女生向前冲',
                {
                  style:
                  {
                    fontColor: Color.Blue,
                    fontSize: 30
                  }
                })
            })
            .onAreaChange((_, value) => {
              if (_.height !== value.height) {
                this.scroller.scrollBy(0, Number(value.height) - 200)
                console.log('---_.height', _.height)
                console.log('---value.height', value.height)
              }
            })
          Button('getSpans-文字').onClick((event: ClickEvent) => {
            let getSpans = this.editorController.getSpans({ start: 0 })
            console.log('getSpans0' + JSON.stringify(getSpans[0]))
            // Strong casting is required to obtain text or image information
            let span0 = getSpans[0] as RichEditorTextSpanResult
            console.log('Text-related information: ' + JSON.stringify(span0))
          })
          Button('getSpans-图片').onClick((event: ClickEvent) => {
            let getSpans = this.editorController.getSpans({ start: 0 })
            console.log('getSpans1' + JSON.stringify(getSpans[1]))
            let span1 = getSpans[1] as RichEditorImageSpanResult
            console.log('Image-related information: ' + JSON.stringify(span1))
          })
          Button('RichEditor获焦').onClick(() => {
            focusControl.requestFocus('RichEditor')
          })
        }
      }
      .scrollable(ScrollDirection.Vertical) // Vertical scrolling direction
      .scrollBar(BarState.On) // Scrollbar always visible
      .scrollBarColor(Color.Gray) // Scrollbar color
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

4. Why Do Performance Issues Occur When Storing Complex Objects in LocalStorage or APPStorage?

Two questions about performance issues when storing complex objects in LocalStorage and APPStorage:

  1. Frequent Reading/Writing: Why does frequent reading/writing of complex objects degrade page performance? Does LocalStorage affect page rendering?
  2. Data Structure: Are data stored locally in LocalStorage and APPStorage? They should be in memory—why does serialization/deserialization occur?

Answers:

  • LocalStorage operations are synchronous. When reading/writing, the program blocks until the operation completes, which affects refresh efficiency, especially for complex objects.
  • LocalStorage and APPStorage do not serialize complex objects when reading them locally.

5. Error When Using Synchronous Methods to Get Network Status in a No-Network Environment?

In a no-network environment, calling synchronous methods cannot parse the corresponding nethandle content, and an error occurs when the method internally executes getCap. Use try-catch to get the error information:

try {
  let netHandle = connection.getDefaultNetSync();
  let connectionproperties = connection.getConnectionPropertiesSync(netHandle);
} catch(err) {
  console.info('error: ' + JSON.stringify(err));
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)