wx.createRewardedVideoAd
wx.createRewardedVideoAd(Object object)
Feature description:Creates a rewarded video ad component. The rewarded video ad created by calling this method is a singleton (a global singleton in a mini game, and a singleton within a page in a mini program. The singleton object in the mini program cannot be used across pages.)
Parameter: Object object.
|
adUnitId | string | - | True | Ad unit ID. |
multiton | boolean | - | False | Whether to enable multiple-instance mode. Default: false. |
RewardedVideoAd
Rewarded video ad component. The rewarded video ad is a native component with a higher level than regular components. Each rewarded video ad is a singleton, which is hidden by default and you need to call RewardedVideoAd.show() to display it.
Method
RewardedVideoAd.load()
Feature description:Loads a rewarded video ad.
Return value:Promise. The result of loading data for a rewarded video ad.
RewardedVideoAd.show()
Feature description:Displays a rewarded video ad. The rewarded video ad will slide up from the bottom of the screen.
Return value:Promise, the result of displaying the rewarded video ad.
RewardedVideoAd.destroy()
Feature description:Destroys a rewarded video ad instance.
RewardedVideoAd.onLoad(function listener)
Feature description:Listens for the rewarded video ad loading event.
Parameter: function listener. The listener for the rewarded video ad loading event.
RewardedVideoAd.offLoad(function listener)
Feature description:Removes the listener for the rewarded video ad loading event.
Parameter: function listener. The listener that was passed to onLoad. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }
RewardedVideoAd.onLoad(listener)
RewardedVideoAd.offLoad(listener)
RewardedVideoAd.onError(function listener)
Feature description:Listens for rewarded video error events.
Parameter: function listener. The listener for rewarded video error events.
Return parameter: Object res.
|
errMsg | string | Error information. |
| number | Error code. |
RewardedVideoAd.offError(function listener)
Feature description:Removes the listener for rewarded video error events.
Parameter: function listener. The listener that was passed to onError. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }
RewardedVideoAd.onError(listener)
RewardedVideoAd.offError(listener)
RewardedVideoAd.onClose(function listener)
Feature description:Listens for the event when a user taps the close
button.
Parameter: function listener. The listener for the event when a user taps the close
button.
Return parameter: Object res.
|
isEnded | boolean | Indicates whether the video was closed after being fully watched by the user. |
RewardedVideoAd.offClose(function listener)
Feature description:Removes the listener for the event when a user taps the close
button.
Parameter: function listener. The listener that was passed to onClose. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }
RewardedVideoAd.onClose(listener)
RewardedVideoAd.offClose(listener)
wx.createBannerAd
wx.createBannerAd(Object object)
Feature description:Creates a banner ad component. Each time this method is called to create a banner ad, a new instance is returned.
Parameter: Object object.
|
adUnitId | string | - | True | Ad unit ID. |
style | Object | - | True | The style of the banner ad component. |
The value of style is as follows:
|
left | number | - | True | The top-left X coordinate of the banner ad component. |
top | number | - | True | The top-left Y coordinate of the banner ad component. |
width | number | - | True | The width of the banner ad component. |
height | number | - | True | The height of the banner ad component. |
Return value:BannerAd.A banner ad component. BannerAd
The banner ad component, which is a native component with a higher level than regular components. The banner ad component is hidden by default and you need to call BannerAd.show() to display it. The banner ad will be scaled proportionally to the width set by the developer, and the scaled size will be provided using the BannerAd.onResize() event.
Property
Object style
The style of the banner ad component. The values of the style properties represent only the developer-defined settings. The banner ad will be scaled proportionally to the width set by the developer, and the scaled size will be provided using the BannerAd.onResize() event.
|
left | number | The top-left X coordinate of the banner ad component. |
top | number | The top-left Y coordinate of the banner ad component. |
width | number | The width of the banner ad component. The minimum value is 300 px, and the maximum value is the screen width (obtained using wx.getSystemInfoSync()). |
height | number | The height of the banner ad component. |
realWidth | number | The actual width of the banner ad component after proportional scaling. |
realHeight | number | The actual height of the banner ad component after proportional scaling. |
Method
BannerAd.show()
Feature description:Shows a banner ad.
Return value: Promise. The result of displaying the rewarded video ad.
BannerAd.hide()
Feature description:Hides a banner ad.
BannerAd.destroy()
Feature description:Destroy a banner ad.
BannerAd.onResize(function listener)
Feature description:Listens for the banner ad size change event.
Parameter: function listener. The listener for the banner ad size change event.
Return parameter: Object res.
|
width | number | Scaled width. |
height | number | Scaled height. |
BannerAd.offResize(function listener)
Feature description:Removes the listener for the banner ad size change event.
Parameter: function listener. The listener that was pass to onResize. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }
BannerAd.onResize(listener)
BannerAd.offResize(listener)
BannerAd.onLoad(function listener)
Feature description:Listens for the banner ad loading event.
Parameter: function listener. The listener for the banner ad loading event.
BannerAd.offLoad(function listener)
Feature description:Removes the listener for the banner ad loading event.
Parameter: function listener. The listener that was passed to onLoad. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }
BannerAd.onLoad(listener)
BannerAd.offLoad(listener)
BannerAd.onError(function listener)
Feature description:Listens for banner ad error events.
Parameter: function listener. The listener for banner ad error events.
Return parameter: Object res.
|
errMsg | string | Error information. |
| number | Error code. |
BannerAd.offError(function listener)
Feature description:Removes the listener for banner ad error events.
Parameter: function listener. The listener that was passed to onError. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }
BannerAd.onError(listener)
BannerAd.offError(listener)
Error code
Error codes are obtained through the onError event. During debugging, you can capture error details via exception returns. You can add appropriate monitoring information to assist in troubleshooting issues in the live environment.
|
1000 | Failed to call the backend API | This error is not caused by the developer. |
1001 | Parameter error | Incorrect usage. |
1002 | Invalid ad unit | Incorrect ad unit ID spelling or accidental use of another app's ad unit ID. |
1003 | Internal error | This error is not caused by the developer. |
1004 | No suitable ad | Ads do not appear every time; this time it might not appear because there are no ads that match the user's preferences. |
1010 | Ad feature disabled | The ad feature has been disabled. |