Customize title bar favorite/unfavorite button

The super app can customize the appearance of the title bar favorite/unfavorite button to ensure a consistent user interface. This button allows user to add or remove a mini program from their favorites. To customize the button, the super app must implement the GRVTitleBarInfoDelegate protocol. This topic covers the default user experience, implementation steps, and protocol details.

Default user experience

By default, the title bar favorite/unfavorite button is a star-shaped icon. Refer to the following table for UI examples:

Add to favorites

Remove from favorites

IMG_2983.PNG

Simulator Screenshot - iPhone 16 Pro - 2025-07-08 at 14.43.33.png

Before you begin

To customize the user interface for the title bar favorite/unfavorite button, ensure that the integrated iOS IAPMiniProgram SDK is version 2.65.3 or later. For more information, see SDK release notes.

Procedure

To customize the title bar favorite/unfavorite button, take the following two steps:

Step 1: Implement the GRVTitleBarInfoDelegate protocol

Define a class that implements the GRVTitleBarInfoDelegate protocol. Within the class, implement the getTitleBarItemInfo method to customize the title bar favorite/unfavorite button. Refer to the following code for a sample implementation. For more information about the protocol and the method, refer to GRVTitleBarInfoDelegate.

copy
class DemoTitleBarInfoDelegate: NSObject, GRVTitleBarInfoDelegate {
    func getTitleBarItemInfo(_ type:GRVTitleBarItemType, status status:GRVTitleBarItemStatus) -> GRVTitleBarItemInfo {

        let titleBarInfo = GRVTitleBarItemInfo.init();
        // Customize the button based on the type and status parameters
        return titleBarInfo;
    }
}

Step 2: Configure titleBarInfoDelegate

After initializing the SDK, create an instance of GRVExtensionDelegate and assign the implementation (for example, DemoTitleBarInfoDelegate in the sample) to the titleBarInfoDelegate property of the delegate's uiProvider. Refer to the following sample configuration code:

copy
let extensionDelegate = GRVExtensionDelegate()
extensionDelegate.uiProvider.titleBarInfoDelegate = DemoTitleBarInfoDelegate()

Structures

GRVTitleBarInfoDelegate protocol

TheGRVTitleBarInfoDelegate protocol defines a method for the super app to customize the title bar favorite/unfavorite button, which the SDK then calls to render the custom button. Refer to the following code for the protocol definition:

copy
@protocol GRVTitleBarInfoDelegate<NSObject>

- (GRVTitleBarItemInfo *)getTitleBarItemInfo:(GRVTitleBarItemType)type status:(GRVTitleBarItemStatus)status;

@end

The following table lists the details of the defined method:

Method

Description

getTitleBarItemInfo:type:status:

Called by the SDK to obtain and render the custom title bar favorite/unfavorite button. For more information, refer to getTitleBarItemInfo:type:status:.

getTitleBarItemInfo:type:status: method

Parameters

This method has the following input parameters:

Parameter

Data type

Required

Description

type

GRVTitleBarItemType

Yes

The button type. Valid value is:

  • GRVTitleBarItemTypeCollect: The favorite/unfavorite button.

For more information, refer to GRVTitleBarItemType.

status

GRVTitleBarItemStatus

Yes

The state of the favorite/unfavorite button. Valid values are:

  • GRVTitleBarItemStatusCollectOn: Indicates the mini program is currently favorited.
  • GRVTitleBarItemStatusCollectOff: Indicates the mini program is currently unfavorited.

For more information, refer to GRVTitleBarItemStatus.

GRVTitleBarItemType
copy
typedef NSString *GRVTitleBarItemType NS_TYPED_EXTENSIBLE_ENUM;
FOUNDATION_EXPORT GRVTitleBarItemType const GRVTitleBarItemTypeCollect;
GRVTitleBarItemStatus
copy
typedef NSString *GRVTitleBarItemStatus NS_TYPED_EXTENSIBLE_ENUM;
FOUNDATION_EXPORT GRVTitleBarItemStatus const GRVTitleBarItemStatusCollectOn;
FOUNDATION_EXPORT GRVTitleBarItemStatus const GRVTitleBarItemStatusCollectOff;
Return value

The method returns an instance of the GRVTitleBarItemInfo object. Refer to the following code for the object definition:

copy
@interface GRVTitleBarItemInfo : NSObject

@property(nonatomic,copy) NSString *iconPath;
@property(nonatomic,copy) NSString *darkIconPath;
@end

The object contains the following properties for the super app to customize the favorite/unfavorite button:

Property

Data type

Required

Description

iconPath

String

Yes

The icon path for light mode.

darkIconPath

String

Yes

The icon path for dark mode.