# hxphone-sdk-demo-iOS **Repository Path**: coremail/hxphone-sdk-demo-iOS ## Basic Information - **Project Name**: hxphone-sdk-demo-iOS - **Description**: hxphone基于iOS平台的sdk集成应用,具备邮件到达通知能力。 - **Primary Language**: Objective-C - **License**: MPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2020-05-14 - **Last Updated**: 2023-06-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # LKMailSDK使用说明 ## 说明 * 项目Deployment Target: 8.0 * SDK提供两个版本:.xcframework和.framework(Xcode11及之后推荐.xcframework,以下以framework举例,xcframework同理) ## 添加SDK 1. Xcode11及之后版本建议选择`LKMailSDK.xcframework`,之前的版本选择`LKMailSDK.framework` 2. 将步骤1选中的sdk拖拽添加到项目中,选中项目中的SDK, 拖入Xcode项目中,选中`Copy Items If Needed`, `Add to targets`选中目标Target。 ![image](README_IMG/importSDK.jpg) 3. Embed & Sign。选中目标Target -- General -- Frameworks, Libraries, and Embedded Content -- 将Embed选项改为`Embed & Sign`。 ![image](README_IMG/Embed.jpg) 4. 检查 Link Binary With Libraries 是否也正确导入 ![image](README_IMG/LinkBinary.jpg) 5. 运行项目。 ## SDK使用 ### 选择登录方式 LKMailSDKProtocol 协议提供两种登录方式:单点登录和账号密码登录。**二者选其一**。 * 单点登录需要提供 userToken,userToken 即为当前用户的登录凭证,SDK 传递这个凭证到邮箱后台,邮箱后台再到用户后台环境去校验这个凭证是否合法,如果合法,邮箱后台会生成一个会话返回给 SDK 使用。 * 账号密码登录,只需要传递账号密码等信息给到 SDK 进行登录即可。 ### 使用 1. 引入头文件 `#import ` 2. LKMailSDKManager 2.1 用`- (instancetype)initWithServerUrl:(NSString *)serverUrl`实例化,参数 serverUrl 为对应的邮箱服务器地址 2.2 赋值`id delegate`属性,并实现对应的协议方法 2.3 `listener`监听操作回调 3. LKReadMailVC 3.1 用`- (instancetype)initWithManager:(LKMailSDKManager *)manager`实例化,将第2步的 LKMailSDKManager 实例传入 ### 简单示例 ``` #import - (void)showMailList { LKMailSDKManager* manager = [[LKMailSDKManager alloc] initWithServerUrl:@"邮箱服务器地址"]; manager.delegate = self; manager.debugMode = true; manager.useCloudHxphone = false; manager.enableWKWebView = true; manager.listener = ^(LKMailAction action, id info, NSError *error) {}; LKReadMailVC* mailVC = [[LKReadMailVC alloc] initWithManager: manager]; UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:mailVC]; navi.modalPresentationStyle = UIModalPresentationFullScreen; [self.navigationController presentViewController:navi animated:true completion:nil]; } ...... #pragma mark - LKMailSDKProtocol - (LKMailAccount *)account { LKMailAccount* account = [[LKMailAccount alloc] initWithUserName:@"账号" password:@"密码"]; account.verifyCode = @"图形验证码(选填)"; account.tempSid = @"listener回调的临时sid(选填)"; account.smsCode = @"短信验证码(选填)"; account.dynamicCode = @"动态验证码(选填)"; return account; } ``` ### API介绍 #### LKMailSDKManager * `debugMode`默认 NO。开启 debug 模式,控制台会有相应输出,进入邮件列表界面,连续点击导航栏3下进入日志列表页,日志按日期分类,可点击查看对应日期的使用日志。 * `useCloudHxphone`默认 NO。有两种配置方式,一种通过请求获取邮件数据,使用本地资源展示邮件数据,另一种是读取服务器上的 hxphone 网页展示邮件数据(即云端移动模板)。默认 NO 是使用第一种方式。 * `enableWKWebView`默认 YES。默认情况下会自动根据系统选择,如果是iOS 11及以上系统,使用 WKWebview,11以下系统使用 UIWebview。设置为 NO,则强制使用 UIWebview。 * `listener`监听SDK使用情况,具有`LKMailAction action, id info, NSError* error`三个参数。 * `customUserAgent`用户自定义的UserAgent * 推送(前提:自建的邮箱服务器有推送服务) * `- (void)registerApplePushWithDeviceToken:(NSData *)deviceToken`注册推送,传入注册苹果推送返回的deviceToken。 * `- (void)unRegisterApplePushWithDeviceToken:(NSData *)deviceToken`取消推送,传入注册苹果推送返回的deviceToken。建议账号退出登录时调用。 #### LKReadMailVC * `- (void)readMailWithMid:(NSString *)mid` 指定邮件 id 进行读信。 * `- (void)refreshMailList` 刷新邮件列表,可用于用户环境有新邮件到达时调用刷新。 * `- (void)doClear` 清理方法,**此方法建议只在有需要的情况下使用**,例如有多处同时使用此 SDK,或者 SDK 和远程部署的移动模板一起使用的情况,可以在切换时调用此方法做清理。一般 LKReadMailVC 退出释放时会自动清理缓存。 #### LKMailAccount * 属性`dynamicCode``verifyCode``smsCode``tempSid`都是选填,通过监听 LKMailSDKManager 的 listener 回调的错误提示使用。 ## 其他问题 1. framework只包括了`armv7 arm64`三种架构,只支持真机运行调试,因为模拟器的`x86_64`架构无法上传到App Store。xcframework包含所有架构,Xcode11引入,可以自动选择合适的指令集,推荐使用xcframework。