iOS zendeskSDK 集成调试

2023-03-12  本文已影响0人  New_卡迪熊

客户需要项目中接入客服系统,选用的zendesk

文档介绍,看起来比较简单
https://developer.zendesk.com/documentation/classic-web-widget-sdks/support-sdk/ios/nutshell/

#import <SupportSDK/SupportSDK.h>
#import <ZendeskCoreSDK/ZendeskCoreSDK.h>
#import <SupportProvidersSDK/SupportProvidersSDK.h>
#import <SupportProvidersSDK/ZDKLogger.h>

    [ZDKZendesk initializeWithAppId: @""
                           clientId: @""
                         zendeskUrl: @""];  //这里需要再后台设置好ID 直接拿过来调用
    NSString *NameString = [[NSUserDefaults standardUserDefaults]objectForKey:@"emailcell"];
    id<ZDKObjCIdentity> userIdentity = [[ZDKObjCAnonymous alloc] initWithName:NameString ?: @"xiaoming" email:NameString ? : @"xiaoming@email.com"];

    [[ZDKZendesk instance] setIdentity:userIdentity];
    [ZDKSupport initializeWithZendesk: [ZDKZendesk instance]];
#import <SupportSDK/SupportSDK.h>
#import <ZendeskCoreSDK/ZendeskCoreSDK.h>
#import <SupportProvidersSDK/SupportProvidersSDK.h>

        dispatch_async(dispatch_get_main_queue(), ^{
            
            AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
            UIViewController *helpCenter = [ZDKHelpCenterUi buildHelpCenterOverviewUiWithConfigs:@[]];
            UINavigationController *nav = [UINavigationController new];
            nav.modalPresentationStyle = UIModalPresentationFullScreen;
            
            [nav pushViewController:helpCenter animated:true];
            [delegate.window.rootViewController presentViewController:nav animated:true completion: nil];
        });
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"

EXTRACTED_ARCHS=()

for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done

echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"

echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"

done

另外再附一段请求代码示例

    ZDKRequestProvider *provider = [ZDKRequestProvider new];
    ZDKCreateRequest *request = [ZDKCreateRequest new];

    request.subject = [NSString stringWithFormat:@"%@:%@\n%@:%@\n%@:%@",
                       NSLocalizedString(@"礼品邮箱", nil),emailCell.EmailTextfield.text,
                       NSLocalizedString(@"订单号", nil),orderCell.OrderTextfield.text,
                       NSLocalizedString(@"礼品", nil),self.navtitlestring];  //请求主题
    request.requestDescription = [NSString stringWithFormat:@"%@\n%@:%@\n%@:%@\n%@:%@",
                                  NSLocalizedString(@"礼品", nil),
                                  NSLocalizedString(@"邮箱", nil),emailCell.EmailTextfield.text,
                                  NSLocalizedString(@"订单号", nil),orderCell.OrderTextfield.text,
                                  NSLocalizedString(@"礼品", nil),self.navtitlestring]; //请求描述
//    request.tags = @"iOS"; //标签
    
    [SVProgressHUD showWithStatus:NSLocalizedString(@"Processing...",nil)];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeGradient];
    [provider createRequest:request withCallback:^(id result, NSError *error) {

        if (error) {
            // Handle the error

            // Log the error
            [ZDKLogger e:@"Something went wrong"];
            [SVProgressHUD dismiss];
            [SVProgressHUD showErrorWithStatus:NSLocalizedString(@"上传失败,请重试", nil)];
            [SVProgressHUD dismissWithDelay:3.0];

        } else {

            [[NSUserDefaults standardUserDefaults] setObject:emailCell.EmailTextfield.text forKey:@"emailcell"];
            // 防止循环引用
            __weak typeof(self) weakSelf = self;
          //  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [SVProgressHUD dismiss];
                [weakSelf.navigationController popViewControllerAnimated:NO];
                weakSelf.backBlock();

           // });

        }
    }];

有疑问的小伙伴可以在评论区交流。

上一篇下一篇

猜你喜欢

热点阅读