iOS SDK API

更新时间:
复制 MD 格式

This document describes the APIs for the Mobile Feedback iOS SDK.

SDK initialization (using appKey and appSecret)

/// @brief Initialization method
/// @params anAppKey The AppKey
/// @params anAppSecret The AppSecret
/// @return A YWFeedbackKit instance
- (instancetype)initWithAppKey:(NSString *)anAppKey appSecret:(NSString *)anAppSecret;

Usage:

// Initialize the SDK and manually configure the appKey and appSecret.
self.feedbackKit = [[YWFeedbackKit alloc] initWithAppKey:kAppKey appSecret:kAppSecret];

Get the number of unread messages

Retrieve the number of unread messages in your mobile application.

/// @brief The callback block for the number of unread feedback messages.
/// @params unreadCount The number of unread messages.
/// @return error An error is returned if the call fails.
typedef void (^YWGetUnreadCountCompletionBlock) (NSInteger unreadCount, NSError *error);

/// @brief Requests the number of unread feedback messages.
- (void)getUnreadCountWithCompletionBlock:(YWGetUnreadCountCompletionBlock)completionBlock;

Usage:

/** Query the number of unread messages */
- (void)fetchUnreadCount {
    __weak typeof(self) weakSelf = self;
    // feedbackKit is the held iOS SDK kit.
    [self.feedbackKit getUnreadCountWithCompletionBlock:^(NSInteger unreadCount, NSError *error) {
        // The returned block contains the number of unread messages and any errors.
        // Implement subsequent business logic here.
    }];
}

Open or close the Mobile Feedback page

You can open the Mobile Feedback page in your mobile application to perform feedback-related operations.

/// @brief The callback block for creating a feedback page.
/// @params viewController The feedback page.
/// @return error An error is returned if the call fails.
typedef void (^YWMakeFeedbackViewControllerCompletionBlock) (YWFeedbackViewController * viewController, NSError *error);

/// @brief Creates a feedback page. By default, pop-up error messages are not displayed.
- (void)makeFeedbackViewControllerWithCompletionBlock:(YWMakeFeedbackViewControllerCompletionBlock)completionBlock;

Receive a callback when the Mobile Feedback page is closed.

/// @brief The block for closing YWFeedbackView.
@property (nonatomic, copy) YWCloseBlock closeBlock;

Usage:

/** Open the user feedback page */
- (void)openFeedbackViewController {
     __weak typeof(self) weakSelf = self;
    [self.feedbackKit makeFeedbackViewControllerWithCompletionBlock:^(YWFeedbackViewController *viewController, NSError *error) {
        // Returns the obtained viewController or an error.
        // If no error occurs, you can get the feedback page viewController and display the page as needed.
        if (viewController != nil) {
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
            [weakSelf presentViewController:nav animated:YES completion:nil];
            
            // Set the callback for closing the feedback page.
            [viewController setCloseBlock:^(UIViewController *aParentController){
                [aParentController dismissViewControllerAnimated:YES completion:nil];
            }];
        } else {
            /** If you use a custom method to throw an error, comment out this section. */
            NSString *title = [error.userInfo objectForKey:@"msg"]?:@"API call failed. Make sure your network is connected.";
            [[TWMessageBarManager sharedInstance] showMessageWithTitle:title
                                                           description:nil
                                                                  type:TWMessageBarMessageTypeError];
        }
    }];
}

Set a username

You can set a username to identify the user. Once set, the username appears in the session view of the Mobile Feedback console.

/**
 Set the feedback username. Call this after the SDK is initialized.
 (This username appears in the feedback session view of the Mobile Feedback console to identify the user.)
 @param nickName The feedback username.
 */
- (void)setUserNick:(NSString *)nickName;

Usage:

[self.feedbackKit setUserNick:@"***"];

Set custom extension information

You can set custom extension information, which will be displayed in the Mobile Feedback console.

/// @brief Extended feedback data from the business side. Set this before creating the feedback page.
@property (nonatomic, strong, readwrite) NSDictionary *extInfo;

Usage:

 /** Set custom extended feedback data for the app */
 // Set before entering the feedback page.
self.feedbackKit.extInfo = @{@"loginTime":[[NSDate date] description],
                                 @"visitPath":@"Log on->About->Feedback",
                                 @"userid":@"yourid",
                                 @"app_custom_extended_info":@"Developers can set different custom information as needed for easy viewing in the feedback system."};

Set a custom error view

You can set this property to customize the error view.

/// @brief The callback block for when the feedback page throws an error. If this property is not set, a default alert is used for error prompts.
/// @params viewController The feedback page.
/// @return error The error that occurred.
@property (nonatomic, copy) void (^YWFeedbackViewControllerErrorBlock) (YWFeedbackViewController *viewController, NSError *error);

Usage:

/** Use a custom method to throw an error */
[self.feedbackKit setYWFeedbackViewControllerErrorBlock:^(YWFeedbackViewController *viewController, NSError *error) {
    NSString *title = [error.userInfo objectForKey:@"msg"]?:@"API call failed. Make sure your network is connected.";
    [[TWMessageBarManager sharedInstance] showMessageWithTitle:title
                                                   description:[NSString stringWithFormat:@"%ld", error.code]
                                                          type:TWMessageBarMessageTypeError];
}];

Set the font for navigation bar buttons on the user feedback page

/// @brief If not set, the default is: `[UIFont boldSystemFontOfSize:13]`
@property (nonatomic, strong) UIFont *defaultCloseButtonTitleFont;

/// @brief If not set, the default is: `[UIFont boldSystemFontOfSize:13]`
@property (nonatomic, strong) UIFont *defaultRightBarButtonItemTitleFont;

Usage:

self.feedbackKit.defaultCloseButtonTitleFont = [UIFont systemFontOfSize:18];
self.feedbackKit.defaultRightBarButtonItemTitleFont= [UIFont systemFontOfSize:20];