测试已测试 | ✓ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最新版本发布时间 | 2016年4月 |
由 Herbert Bay 和 Severin Schoepke 维护。
此 SDK 提供以下功能:
此 SDK 还有 Android 版本。
此 SDK 与所有运行 iOS6 及以上版本设备的设备兼容。
您可以使用 CocoaPods 或将其作为 .framework 文件集成到您的应用程序中来安装此 SDK。
为了使用此 SDK,您需要以下内容:
要使用深链接功能,还需要以下内容:
确保在所有使用 SDK 的文件中导入我们的 SDK
#import <Shortcut/Shortcut.h>
使用Shortcut Manager创建一个带有相关API键的移动应用。然后,通过在您的AppDelegate.m文件中的-application:didFinishLaunchingWithOptions:
中添加以下内容来使用API键的认证令牌启动SDK:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[Shortcut launchWithAuthToken:@"YOUR_AUTH_TOKEN_HERE"];
// ...
return YES;
}
要收集深链接交互统计信息,您需要在深链接打开时通知SDK:SDK通过会话跟踪用户查看深链接内容。每次打开一个深链接时,您都必须创建一个会话;当用户离开您的应用程序时,SDK将自动终止该会话。
将以下内容添加到-application:openURL:sourceApplication:annotation:
(您在实现应用程序自定义方案深链接处理时已将其添加到应用程序代理中):
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
SCSession *deepLinkSession = [Shortcut startDeepLinkSessionWithURL:url];
url = deepLinkSession.url; // Use the session object's url property for further processing
// ...
}
将以下内容添加到-application:continueUserActivity:restorationHandler:
(您在实现应用程序通用链接处理时已将其添加到应用程序代理中):
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
self.deepLinkSession = [Shortcut startDeepLinkSessionWithURL:userActivity.webpageURL];
userActivity.webpageURL = self.deepLinkSession.url; // Use the session object's url property for further processing
}
// ...
}
快捷方式允许您立即生成短链接,无需(可能是缓慢的)后端往返操作。其工作方式如下:
这样您就可以立即获得一个链接,将其显示在分享选项卡中或通过电子邮件发送出去,无需等待后端。
重要提示:您必须确保在调用此方法时网络连接可用!
示例:假设您有一个分享按钮,它应弹出一个操作表单,允许您通过短链接在您的应用程序中分享某些内容。
实现可能如下所示:
- (IBAction)shareButtonPressed:(id)button {
NSURL *shortLinkURL = [Shortcut createShortLinkWithTitle:@"content title"
websiteURL:[NSURL URLWithString:@"http://your.site/content"]
deepLink:[NSURL URLWithString:@"your-app://your/content"]];
[self displayShareSheetWithURL:shortLinkURL];
}
- (void)displayShareSheetWithURL:(NSURL *)urlToShare {
// ...
}
还有创建新短链接的异步方式。其工作方式如下:
这样您需要等待后端生成短链接,但如果发生任何错误(例如,没有网络连接),则可以对其进行响应。
上述示例的实现方式可以通过异步调用如下所示:
- (IBAction)shareButtonPressed:(id)button {
[Shortcut createShortLinkWithTitle:@"content title"
websiteURL:[NSURL URLWithString:@"http://your.site/content"]
deepLink:[NSURL URLWithString:@"your-app://your/content"]
completionHandler:^(NSURL *shortLinkURL, NSError *error) {
if (!error) {
[self displayShareSheetWithURL:shortLinkURL];
} else {
// do error handling...
}}];
}
- (void)displayShareSheetWithURL:(NSURL *)urlToShare {
// ...
}
如果您支持的不同平台(iOS、Android、Windows Phone)上的深链接不相同,则可以在每个平台上指定它们,只需使用 [Shortcut createShortLinkWithTitle:websiteURL:iOSDeepLink:AndroidDeepLink:WindowsPhoneDeepLink:]
或 [Shortcut createShortLinkWithTitle:websiteURL:iOSDeepLink:AndroidDeepLink:WindowsPhoneDeepLink:completionHandler:]
即可。
如果您在快捷方式管理器中设置了自定义域名以便为您的短链接使用,并且想要同时将SDK创建的短链接也用于该域名,则您需要告诉SDK这一信息。这通过使用自定义域名参数启动SDK来实现。只需将您的AppDelegate.m文件中的-application:didFinishLaunchingWithOptions:
中的SDK启动调用进行替换即可
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[Shortcut launchWithAuthToken:@"YOUR_AUTH_TOKEN_HERE" shortLinkDomain:@"YOUR_DOMAIN_HERE"]; // instead of: [Shortcut launchWithAuthToken:@"YOUR_AUTH_TOKEN_HERE"];
// ...
return YES;
}
Shortcut Deep Linking SDK已被弃用,其功能已集成到本SDK/Shortcut for iOS中。
请按照以下步骤迁移您的代码以使用此新SDK
ShortcutDeepLinkingSDK.framework
。#import <ShortcutDeepLinkingSDK/ShortcutDeepLinkingSDK.h>
替换为#import <Shortcut/Shortcut.h>
。Shortcut
类上的类方法来进行所有交互,而不是使用SCDeepLinking
类的单例实例的方法。因此,您必须替换代码中所有以下对SDK的调用[[SCDeepLinking sharedInstance] launch]
替换为[Shortcut launchWithAuthToken:]
[[SCDeepLinking sharedInstance] startSessionWithURL:]
替换为[Shortcut startDeepLinkSessionWithURL:]
[[SCDeepLinking sharedInstance] createShortLinkWithTitle:websiteURL:deepLinkURL:completionHandler:]
替换为[Shortcut createShortLinkWithTitle:websiteURL:deepLink:completionHandler:]
[Shortcut createShortLinkWithTitle:websiteURL:deepLink:completionHandler:]
的调用替换为[Shortcut createShortLinkWithTitle:websiteURL:deepLink:]
。本项目遵循MIT许可证发布。有关详细信息,请参阅包含的LICENSE.txt文件。