ShippedSuite iOS SDK
Shipped Shield 提供丢失、损坏或被盗的货物运输的高级包裹保证。通过应用程序轻松跟踪和解决货物运输问题,无需费心。
例子
要运行示例项目,请首先克隆仓库,然后从 Example 目录运行 pod install
命令。
要求
ShippedSuite iOS SDK 需要 Xcode 13.3.1 或更高版本,并与针对 iOS 11.0 或更高版本的 App 兼容。
安装
ShippedSuite iOS SDK 通过 CocoaPods、Carthage、SPM 提供使用。
CocoaPods
如果您还没有安装,请安装最新版本的 CocoaPods。如果您还没有现有的 Podfile
,请运行以下命令来创建一个:
pod init
在您的 Podfile 中添加以下行
pod 'ShippedSuite'
运行以下命令
pod install
记住使用 .xcworkspace
文件在 Xcode 中打开项目,而不是 .xcodeproj
文件。从现在开始,要更新到 SDK 的最新版本,只需运行
pod update ShippedSuite
Carthage
如果您还没有安装%,请安装最新版本的 Carthage。要使用它,您需要一个 Cartfile
并将此行添加到您的 Cartfile:
github "InvisibleCommerce/shipped-suite-ios-client-sdk"
运行以下命令
carthage update --use-xcframeworks
将构建的 .xcframework
包拖放到您的应用程序 Xcode 项目的“框架和库”部分中的 Carthage/Build
。
Swift Package Manager
设置
导入SDK。
#import <ShippedSuite/ShippedSuite.h>
使用您的ShippedSuite可发布API密钥配置SDK。
[ShippedSuite configurePublicKey:@"Public key"];
如果想在不同的端点上测试,可以自定义模式。默认是开发模式,所以在生产构建时请确保切换到生产模式。
[ShippedSuite setMode:ShippedSuiteProductionMode];
创建带有优惠的Widget视图
可以将其初始化并放置在需要的位置。
ShippedSuiteConfiguration *configuration = [ShippedSuiteConfiguration new];
configuration.type = ShippedSuiteTypeGreen;
configuration.isInformational = YES;
configuration.isMandatory = NO;
configuration.isRespectServer = NO;
configuration.currency = @"USD";
configuration.appearance = ShippedSuiteAppearanceAuto;
SSWidgetView *widgetView = [[SSWidgetView alloc] initWithFrame:CGRectMake(x, y, width, height)];
widgetView.configuration = configuration;
widgetView.delegate = self;
或者可以在故事板中使用它。
每当购物车价值更改时,使用最新购物车价值更新Widget视图。此值应该是订单项价值的总和,在折扣、运费、税费等之前。
[widgetView updateOrderValue:cartValueRoundedNumber];
要从Widget获取回调,您需要实现SSWidgetViewDelegate
委托。
#pragma mark - SSWidgetViewDelegate
- (void)widgetView:(SSWidgetView *)widgetView onChange:(NSDictionary *)values
{
BOOL isSelected = [values[SSWidgetViewIsSelectedKey] boolValue];
NSLog(@"Widget state: %@", isSelected ? @"YES" : @"NO");
NSDecimalNumber *totalFee = values[SSWidgetViewTotalFeeKey];
if (totalFee) {
NSLog(@"Total fee: %@", totalFee.stringValue);
}
NSError *error = values[SSWidgetViewErrorKey];
if (error) {
NSLog(@"Widget error: %@", error.localizedDescription);
}
}
Widget state: YES
Shield fee: 2.27
Green fee: 0.39
在回调中,根据SSWidgetViewIsSelectedKey
是否为true或false,实现添加或删除Shield或Green到购物车的任何必要逻辑。
自定义
如果您打算自己实现Widget以适应应用样式,您仍然可以使用SDK提供的功能。
- 请求优惠费
[ShippedSuite getOffersFee:[[NSDecimalNumber alloc] initWithString:_textField.text] currency:@"EUR" completion:^(SSOffers * _Nullable offers, NSError * _Nullable error) {
if (error) {
NSLog(@"Failed to get offers fee: %@", error.localizedDescription);
return;
}
NSLog(@"Get shield fee: %@", offers.shieldFee.stringValue);
NSLog(@"Get green fee: %@", offers.greenFee.stringValue);
}];
- 显示了解更多模态框
SSLearnMoreViewController *controller = [[SSLearnMoreViewController alloc] initWithConfiguration:self.configuration];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller];
if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.preferredContentSize = CGSizeMake(650, 600);
}
[self presentViewController:nav animated:YES completion:nil];
故障排除
Q: 缺失的资产
请按照以下步骤进行检查
- 前往项目的根文件夹,运行
gem install cocoapods
升级 CocoaPods - 运行
pod install
- 确保生成了针对正确目标的
Copy Pods Resources
脚本(如以下截图所示)- 如果脚本没有自动生成,您可以在
Podfile
中检查它是否已正确配置为您的目标。 - 您也可以手动配置它,在左上角点击 ➕,选择
New Run Script Phase
,填写脚本,Input File Lists
和Output File Lists
,请记住替换您Pods
文件夹中的文件名。
- 如果脚本没有自动生成,您可以在
- 运行它
许可协议
ShippedSuite 在 MIT 许可协议下可用。有关更多信息,请参阅 LICENSE 文件。