LivePaperSDK 2.0.1

LivePaperSDK 2.0.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布Jul 2017

Alejandro Mendez 维护。



  • a1cf64a6c93c5292335a0e92ef14cae19862967c

链接 iOS 开发者 SDK

提供 Objective C 接口,通过 HP 的 "Link" 服务创建带水印的图片、二维码和手机友好的缩短 URL。

手动安装

要手动包含 Link iOS 开发者 SDK,请按照以下步骤操作

  • 从 github 克隆 SDK - https://github.com/IPGPTP/live_paper_sdk.
  • 构建 LivePaperSDK 生成框架
    • 进入 LivePaperSDK 文件夹并运行 pod install.
    • 打开 "LivePaperSDK.xcworkspace" 工作空间。
    • 选择 "LivePaperSDK-Universal" 方案并构建它。
    • 在框架生成后,将打开一个窗口,其中包含 "LivePaperSDK.framework" 文件。
  • 将 "LivePaperSDK.framework" 框架拖动到您的 Xcode 项目中。当提示时,选择“将项目复制到目标组的文件夹”。
  • 通过点击 + 按钮 > 新建 Copy Files 阶段来添加一个新的构建阶段。新的阶段将创建在构建阶段列表的末尾。
  • 在您刚刚创建的 Copy Files 阶段中,点击以打开详细信息披露箭头并按如下配置
    • 目标:框架
    • 在列表下方点击 + 按钮,在出现的模态窗口中找到 LivePaperSDK.framework;点击添加
    • 选择“复制项时进行代码签名”
  • 在发布时,在将应用发布到 App Store 将使用的目标中添加一个新的“运行脚本”阶段,其内容如下
bash "$BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/LivePaperSDK.framework/release_strip_archs.sh"

验证身份

在源文件顶部导入 LivePaperSDK.h

#import <LivePaperSDK/LivePaperSDK.h>

然后使用您的客户端 ID 和密钥创建一个新的会话。

LPSession *lpSession = [LPSession createSessionWithClientId:"your client id" secret:"your client secret"];

快速入门使用

缩短 URL

要缩短 URL,最简单的方法是使用 LPSession 的 createShortUrl:destination:completionHandler 方法。

NSString *name = @"My Short URL";
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
[lpSession createShortUrl:name destination:url completionHandler:^(NSURL *shortUrl, NSError *error) {
  if (shortUrl) {
    [self showAlert:@"Created ShortURL" message:[shortUrl absoluteString]];
  } else {
    [self showAlert:@"Error" message:[error description]];
  }
}];

生成 QR 码

要创建 QR 码,最简单的方法是使用 LPSession 的 createQrCode:destination:completionHandler 方法。指定扫描 QR 码时应跳转到的 URL。

NSString *name = @"My QR Code";
NSURL *url = [NSURL URLWithString:@"https://www.amazon.com"];
[lpSession createQrCode:name destination:url completionHandler:^(UIImage *image, NSError *error) {
  if (image) {
    [self showAlert:@"Created QrCode" image:image];
  } else {
    [self showAlert:@"Error" message:[error description]];
  }
}];

目前,Link 开发者 SDK 只返回 jpg 格式的 QR 码图像。

水印图片

要水印图像,最快的方法是使用LPSession的createWatermark:destination:imageURL:completionHandler方法。指定要水印的JPEG图像的URL,以及扫描水印图像时将到达的URL。

NSString *name = @"My Watermark";
NSURL *url = [NSURL URLWithString:@"https://www.hp.com"];
NSURL *imageURL = [NSURL URLWithString:@"https://s3-us-west-1.amazonaws.com/linkcreationstudio.com/developer/zion_600x450.jpg"];
[lpSession createWatermark:name destination:url imageURL:imageURL completionHandler:^(UIImage *watermarkedImage, NSError *error) {
  if (watermarkedImage) {
    [self showAlert:@"Watermarked Image" image:watermarkedImage];
  } else {
    [self showAlert:@"Error" message:[error description]];
  }
}];

目前,链接开发者SDK只返回jpg格式的水印图像。

带有丰厚回报的水印图像

要水印一个通往交互式移动体验的图像,请使用LPSession的createWatermark:richPayoffData:publicURL:imageURL:completionHandler方法。指定要水印的JPEG图像的URL,以及扫描水印图像时应显示的丰厚回报数据。

NSString *name = @"My Watermark With Rich Payoff";
NSURL *url = [NSURL URLWithString:@"https://www.hp.com"];
NSURL *imageURL = [NSURL URLWithString:@"http://static.movember.com/uploads/2014/profiles/ef4/ef48a53fb031669fe86e741164d56972-546b9b5c56e15-hero.jpg"];
NSDictionary *richPayoffData = @{
  @"type" : @"content action layout",
  @"version" : @"1",
  @"data" : @{
    @"content" : @{
      @"type" : @"image",
      @"label" : @"Movember!",
      @"data" : @{
        @"URL" : @"http://static.movember.com/uploads/2014/profiles/ef4/ef48a53fb031669fe86e741164d56972-546b9b5c56e15-hero.jpg"
      }
    },
    @"actions" : @[
      @{
        @"type" : @"webpage",
        @"label" : @"Donate!",
        @"icon" : @{ @"id" : @"533" },
        @"data" : @{ @"URL" : @"http://MOBRO.CO/oamike" }
      },
      @{
        @"type" : @"share",
        @"label" : @"Share!",
        @"icon" : @{ @"id" : @"527" },
        @"data" : @{ @"URL" : @"Help Mike get the prize of most donations on his team! MOBRO.CO/oamike"}
      }
    ]
  }
};
[lpSession createWatermark:name richPayoffData:richPayoffData publicURL:url imageURL:imageURL completionHandler:^(UIImage *watermarkedImage, NSError *error) {
  if (watermarkedImage) {
    [self showAlert:@"Watermarked Image" image:watermarkedImage];
  } else {
    [self showAlert:@"Error" message:[error description]];
  }
}];

用法

iOS链接开发者SDK支持对底层对象的所有CRUD操作。如果您不需要更新或删除之前创建的对象,请参阅上面的快速入门部分。

底层对象

触发器代表您希望放在页面上的对象:一个短网址、二维码或水印图像。回报是目的地,可以是网页URL或交互式移动体验。链接将触发器与回报连接起来。项目代表您在其中创建触发器、回报和链接的实体。

CRUD示例

NSString *name = @"ShortURL Example";
NSString *projectId = @"project id";
NSURL *url = [NSURL URLWithString:@"https://www.hp.com"];
LPSession *lpSession = [LPSession createSessionWithClientId:@"your client id" secret:@"your client secret"];
[LPTrigger createShortUrlWithName:name projectId:projectId session:lpSession completion:^(LPTrigger *trigger, NSError *error) {
  if (trigger) {
    [LPPayoff createWebPayoffWithName:name url:url projectId:projectId session:lpSession completion:^(LPPayoff *payoff, NSError *error) {
      if (payoff) {
        [LPLink createWithName:name triggerId:trigger.identifier payoffId:payoff.identifier projectId:projectId session:lpSession completion:^(LPLink *link, NSError *error) {
          if (link) {
            trigger.shortURL; // returns url of the form http://hpgo.co/abc123
          }
        }];
      }
    }];
  }
}];

创建后,您需要以某种形式将链接、回报和触发器ID持久化,以便稍后访问资源。

如果要更改目的地

LPSession *lpSession = [LPSession createSessionWithClientId:@"your client id" secret:@"your client secret"];
NSString *payoffId = @"payoff id";
NSString *projectId = @"project id";
[LPPayoff get:payoffId projectId:projectId session:lpSession completion:^(LPPayoff *payoff, NSError *error) {
  if (payoff) {
    payoff.url = [NSURL URLWithString:@"http://shopping.hp.com"];
    [payoff update:^(NSError *error) {
      if (!error) {
        payoff.url // returns the new URL
      }
    }];
  }
}];

稍后,如果要删除资源,请执行以下操作(先删除链接以避免资源冲突)

NSString *projectId = @"project id";
NSString *linkId = @"Link Id";
LPSession *lpSession = [LPSession createSessionWithClientId:@"your client id" secret:@"your client secret"];

// delete link first, to avoid resource conflict
[LPLink get:linkId projectId:projectId session:lpSession completion:^(LPLink *link, NSError *error) {
    if (link) {
        [link delete:^(NSError *error) {
            if (!error) {
                // delete trigger
                [LPTrigger get:link.triggerId projectId:projectId session:lpSession completion:^(LPTrigger * _Nullable trigger, NSError * _Nullable error) {
                    if (trigger) {
                        [trigger delete:^(NSError *error) {}];
                    }
                }];

                // delete payoff
                [LPPayoff get:link.payoffId projectId:projectId session:lpSession completion:^(LPPayoff *payoff, NSError *error) {
                    if (payoff) {
                        [payoff delete:^(NSError *error) {}];
                    }
                }];
            }
        }];
    }
}];

您可以使用列表操作列出现有资源。

NSString *projectId = @"project id";
LPSession *lpSession = [LPSession createSessionWithClientId:@"your client id" secret:@"your client secret"];
[LPLink list:lpSession projectId:projectId completion:^(NSArray<LPLink *> *links, NSError *error) {
    links; // returns array of LPLink objects
}];
[LPPayoff list:lpSession projectId:projectId completion:^(NSArray<LPPayoff *> *payoffs, NSError *error) {
    payoffs; // returns array of LPPayoff objects
}];
[LPTrigger list:lpSession projectId:projectId completion:^(NSArray *triggers, NSError *error) {
    triggers; // returns array of LPTrigger objects
}];

二维码示例

NSString *projectId = @"project id";
NSString *name = @"QRCode Example";
NSURL *url = [NSURL URLWithString:@"http://www.hp.com"];
LPSession *lpSession = [LPSession createSessionWithClientId:@"your client id" secret:@"your client secret"];
[LPTrigger createQrCodeWithName:name projectId:projectId session:lpSession completion:^(LPTrigger * _Nullable trigger, NSError * _Nullable error) {
    if (trigger) {
        [LPPayoff createWebPayoffWithName:name url:url projectId:projectId session:lpSession completion:^(LPPayoff *payoff, NSError *error) {
            if (payoff) {
                [LPLink createWithName:name triggerId:trigger.identifier payoffId:payoff.identifier projectId:projectId session:lpSession completion:^(LPLink *link, NSError *error) {
                    if (link) {
                        [trigger getQrCodeImageWithProgress:^(double progress) {
                            // Progress
                        } completion:^(UIImage * _Nullable image, NSError * _Nullable error) {
                            image; // returns QR Code image
                        }];
                    }
                }];
            }
        }];
    }
}];

水印图像示例

NSString *projectId = @"project id";
NSString *name = @"Watermark Example";
UIImage *image = [UIImage imageNamed:@"image_to_watermark"];
NSData *imageData = UIImageJPEGRepresentation(image, 0.95);
NSURL *url = [NSURL URLWithString:@"http://www.hp.com"];
LPSession *lpSession = [LPSession createSessionWithClientId:@"your client id" secret:@"your client secret"];
[LPTrigger createWatermarkWithName:name projectId:projectId session:lpSession completion:^(LPTrigger * _Nullable trigger, NSError * _Nullable error) {
    if (trigger) {
        [LPPayoff createWebPayoffWithName:name url:url projectId:projectId session:lpSession completion:^(LPPayoff *payoff, NSError *error) {
            if (payoff) {
                [LPLink createWithName:name triggerId:trigger.identifier payoffId:payoff.identifier projectId:projectId session:lpSession completion:^(LPLink *link, NSError *error) {
                    if (link) {
                        // Download watermark image
                        [trigger getWatermarkForImageData:imageData strength:10 watermarkResolution:50 imageResolution:120 adjustImageLevels:YES progress:^(double progress) {
                            // Progress
                        } completion:^(UIImage * _Nullable image, NSError * _Nullable error) {
                            if (image) {
                                image; // returns Watermark image
                            }
                        }];
                    }
                }];
            }
        }];
    }
}];

示例应用

您还可以查看SDK中包含的LivePaperSample应用。此应用演示了如何使用LivePaper iOS SDK。在运行应用程序之前,请将凭证输入到位于LivePaperSDK/LivePaperSample/Controllers/ProjectsTableViewController.swift中的ProjectsTableViewController文件。

let LPP_CLIENT_ID = "CLIENT_ID_HERE"
let LPP_CLIENT_SECRET = "CLIENT_SECRET_HERE"