iOS zendeskSDK 集成调试
2023-03-12 本文已影响0人
New_卡迪熊
客户需要项目中接入客服系统,选用的zendesk
文档介绍,看起来比较简单
https://developer.zendesk.com/documentation/classic-web-widget-sdks/support-sdk/ios/nutshell/
-
1.接下来就是下载SDK了
image.png
可以使用pod 方式
我这边使用的是手动添加
https://github.com/zendesk/zendesk_sdk_ios 下载好直接导入到项目中
同时在build phases 设置
-
2.接下来就是在AppDelegate 调用了
#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]];
- 3.另外再需要调用帮助中心页面直接引用
#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];
});
-
4.就直接显示帮助中心页面
IMG_4082.PNG -
5.最后Xcode 打包时候可能会遇上警告⚠️
image.png -
6.为了避免上架过程中报错 需要加入脚本
image.png
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();
// });
}
}];
有疑问的小伙伴可以在评论区交流。