You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Objective-C阅读器应用中使用ExternalLinkAccount?

Objective-C 配置 Reader App 外部链接账户(ExternalLinkAccount)指南

前提条件

  • 已导入StoreKit框架
  • 你的App符合苹果Reader App定义(仅提供数字内容阅读/访问,无内购解锁新内容等场景)
  • 运行系统版本需为iOS 15.4+(ExternalLinkAccount API最低支持版本)

核心代码实现

直接通过ExternalLinkAccount类的openWithCompletionHandler:方法唤起系统模态提示窗口,代码示例如下:

#import <StoreKit/StoreKit.h>

// 在触发跳转的事件(如按钮点击)中添加以下代码
- (void)triggerExternalRegistrationLink {
    // 先判断系统版本是否支持API
    if (@available(iOS 15.4, *)) {
        [SKExternalLinkAccount openWithCompletionHandler:^(BOOL success, NSError * _Nullable error) {
            if (success) {
                // 用户确认离开App,跳转至你的注册网站
                NSURL *registrationURL = [NSURL URLWithString:@"你的注册网站地址"];
                if ([[UIApplication sharedApplication] canOpenURL:registrationURL]) {
                    [[UIApplication sharedApplication] openURL:registrationURL options:@{} completionHandler:nil];
                }
            } else {
                // 用户取消操作或出现错误
                if (error) {
                    NSLog(@"ExternalLinkAccount 打开失败: %@", error.localizedDescription);
                }
            }
        }];
    } else {
        // 兼容iOS15.4以下版本,直接跳转网站
        NSURL *registrationURL = [NSURL URLWithString:@"你的注册网站地址"];
        if ([[UIApplication sharedApplication] canOpenURL:registrationURL]) {
            [[UIApplication sharedApplication] openURL:registrationURL options:@{} completionHandler:nil];
        }
    }
}

关键注意事项

  • 需在Xcode的Signing & Capabilities中为App添加External Link Account能力
  • 跳转的网站需符合苹果Reader App规则,仅允许提供账户注册、管理类服务,不得包含诱导内购的内容
  • 系统模态窗口的提示文案为苹果默认样式,无法自定义,会告知用户即将离开应用前往目标网站域名

内容的提问来源于stack exchange,提问作者Ted Johnson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 07:10:27