NotifySDK 2.7.0

NotifySDK 2.7.0

Notify Mail.ru 维护。



NotifySDK 2.7.0

  • Libverify Mail.ru

NotifySDK

Notify SDK 是一种用于发送推送通知和通过短信/推送/IVR 验证用户手机号的解决方案。

有两个独立的库 LibnotifyLibverify。它们基于一个称为 NotifyCore 的核心库。还有一个基于 Libverify 开发的库,称为 LibverifyControls。所有库都被包装在动态框架中。

Libnotify

让您处理推送通知并发送事件。为集成到主应用程序、ServiceExtension 和 ContentExtension 而开发。

Libverify

让您通过推送通知或短信验证用户。为集成到主应用程序和 ServiceExtension 而开发。

LibverifyControls

简化了 Libverify 的工作。提供输入电话号码的 UI 解决方案。

演示应用

将很快推出。

清单

以下列表中的各项是正确集成库到应用程序所必需的。

通用

  • 在配置文件中启用框架和库(或库)。
  • 启用调试模式以接收调试信息(但别忘了在发布时禁用调试模式)。

Libnotify

  • 在Notify的配置中设置应用程序标识符和应用程序密钥(应用程序名称已被弃用)。
  • 实现NTFNotifyDelegate协议并将代理安装到[NTFNotify getInstance]
  • 配置活动(阅读'活动设置')。
  • 创建服务扩展并将库'Notify'添加到其中。
  • 创建内容扩展并将库'Notify'添加到其中。

Libverify

  • 在Verify的配置中设置应用程序名称和应用程序ID。
  • 要测试推式通知,您可以在VerifyConfig中启用useSandbox标志。此属性只能通过代码设置,仅在与启用调试模式一起工作时有效。
  • 创建服务扩展并将库'Verify'添加到其中。

LibverifyControls

  • 准备本地化
    • 将字符串 phone-formatter-search-bar-title 设为 搜索,以及将 phone-formatter-navigationItem-title 设为 国家代码,并按需更新主包中的 Localized.strings 文件。
    • 或者您可以实现 NTFPhoneFormatterDelegateconfigureCountriesCodesViewController: 方法,并在视图控制器被展示前对其进行配置。

安装

使用Cocoapods将库添加到项目中

将以下行添加到您的 Podfile 中以添加 Libnotify/Libverify 库支持

Libnotify
pod 'NotifySDK', 'x.x.x' # Please input specific version

pod 'NotifySDK/Notify', 'x.x.x' # Please input specific version
使用UI组件的 Libverify
pod 'NotifySDK/VerifyControls', 'x.x.x' # Please input specific version

或者,如果您想创建自定义组件,可以不使用它们。

pod 'NotifySDK/Verify', 'x.x.x' # Please input specific version
安装这些库
  • 运行 pod install
  • 打开工作空间
注意

您需要将所有目标(对于“Notify”,是您的应用程序和服务扩展,以及内容扩展;对于“Verify”,是您的应用程序和服务扩展)的库添加进去

使用 Carthage 添加库到项目中

即将推出。

用法

  • 创建 NTFAppConfig 实例
  • 使用 NTFApp 初始化框架
  • 配置代理
  • 使用库

配置

您可以从代码中配置 NotifySDK 或者在 plist 格式创建配置文件。底层库使用 NTFAppConfig 的实例进行工作。在初始化之前,您可以更改此配置。但在初始化后,库读取当前状态,不会观察到任何更改。

使用 Notify.plist 创建配置

在使用之前,我们必须配置两个库。最简单的方法是创建文件 Notify.plist。此文件可以配置三个部分:核心(通用属性)、通知和验证。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Enabled</key><!-- Enable or disable framework -->
        <true/>
        <key>Debug</key><!-- Enable or disable debug mode. You have to disable it in Release -->
        <true/>
        <key>LibNotify</key><!-- Configuration of Libnotify -->
        <dict>
            <key>Activity</key><!-- Configuration of activity in libnotify -->
            <dict>
                <key>Colors</key>
                <dict>
                    <key>DarkModeSupported</key><!-- Whether library should configure activity for dark mode or not -->
                    <true/>
                    <key>BackgroundColor</key>
                    <dict>
                        <key>Light</key>
                        <string>#70D05A</string>
                        <key>Dark</key>
                        <string>#70D05A</string>
                    </dict>
                    <key>TextColor</key>
                    <dict>
                        <key>Light</key>
                        <string>#70D05A</string>
                        <key>Dark</key>
                        <string>#70D05A</string>
                    </dict>
                    <key>AccentColor</key>
                    <dict>
                        <key>Light</key>
                        <string>#70D05A</string>
                        <key>Dark</key>
                        <string>#70D05A</string>
                    </dict>
                    <key>ButtonTextColor</key>
                    <dict>
                        <key>Light</key>
                        <string>#70D05A</string>
                        <key>Dark</key>
                        <string>#70D05A</string>
                    </dict>
                    <key>CloseButtonColor</key>
                    <dict>
                        <key>Light</key>
                        <string>#70D05A</string>
                        <key>Dark</key>
                        <string>#70D05A</string>
                    </dict>
                </dict>
                <!-- 
                    You can configure library to use custom fonts or dynamic fonts:
                        Static - enables default fonts and doesn't observe changes in system settings
                        Dynamic - uses default fonts as base font and changes size of font according to system settings
                        Custom - library asks fonts from host application. Library observes system settings and asks new fonts on change them.
                    Default fonts you can find in code.
                -->
                <key>FontType</key>
                <string>Static</string>
            </dict>
            <key>Landing</key><!-- Obsolete! Configuration of landing page -->
            <dict>
                <key>CloseButtonColor</key><!-- Color of button key -->
                <string>#70D05A</string>
                <key>ButtonTextColor</key><!-- Color of buttons text -->
                <string>#FFFFFF</string>
                <key>AccentColor</key><!-- Color of buttons and links -->
                <string>#70D05A</string>
                <key>TextColor</key><!-- Text color -->
                <string>#000000</string>
                <key>BackgroundColor</key><!-- Background color -->
                <string>#FFFFFF</string>
            </dict>
            <key>Enabled</key><!-- Enable or disable Libnotify -->
            <true/>
            <key>Application</key><!-- Libnotify parameters -->
            <dict>
                <key>Name</key><!-- Name of application -->
                <string>application name</string>
                <key>Id</key><!-- Identifier of application -->
                <string>application id</string>
                <key>Secret</key><!-- Secret of application -->
                <string>application secret</string>
            </dict>
        </dict>
        <key>LibVerify</key><!-- Configuration of Libverify -->
        <dict>
            <key>Enabled</key><!-- Enable/disable libverify -->
            <true/>
            <key>DirectPush</key>
            <false/>
            <key>Application</key><!-- Libverify parameters -->
            <dict>
                <key>Name</key>
                <string>application name</string><!-- Application name -->
                <key>Key</key>
                <string>application secret</string><!-- Application key -->
            </dict>
        </dict>
        <key>SharedGroupId</key><!-- Shared group ID. You have to copy group identifier from Entitlements -->
        <string>shared group identifier</string>
    </dict>
</plist>

此配置文件必须添加到应用程序捆绑包中。如果您有 ServiceExtension 或 ContentExtension,您还必须在扩展的捆绑包中添加 Notify.plist。

您可以在包含 pod 的目录中或包含框架的归档中找到示例 Notify.plist

某些属性只能通过代码设置。这是为了安全属性,这些属性很危险,需要更多关注。

其他方法

  • 您可以使用字符串 [NTFAppConfig emptyConfig] 在代码中创建空配置,然后设置所需参数。但请注意并阅读 API 中的注释。

  • 最后,您可以使用方法 [NTFApp defaultConfig] 从 Notify.plist 加载默认配置,然后对其进行更改。

初始化框架

为了初始化框架,您需要使用类 NTFApp。在应用程序和扩展中的应用程序初始化框架的方法不同。

方法 [NTFApp initWithDefaultConfigAndEventsReceiver:] 允许您使用从文件 Notify.plist 加载的配置初始化应用程序的框架。

方法 [NTFApp initExtensionWithDefaultConfigAndEventsReceiver:] 允许您使用从文件 Notify.plist 加载的配置初始化应用程序扩展的框架。

[NTFApp initWithConfig:withEventsReceiver:][NTFApp initExtensionWithConfig:withEventsReceiver:] 方法分别根据自定义配置初始化应用程序和扩展的框架。

初始化框架后,您不能更改配置。

功能

GDRP

Libnotify 支持GDPR。您可以启用或禁用向服务器发送VendorID和WiFi信息。要配置GDRP,您需要使用 -[[NTFNotify getInstance] setDeviceIdTrackingEnabled:boolValue]

提示

  • 如果您只想使用少量配置,您可以为每个配置创建配置文件,使用[NTFAppConfig initWithConfig:]加载所需的配置,并使用此配置初始化框架。

  • 另一种方法是读取基配置文件并修改它。

初始化Libnotify

如果您配置libnotify用于主应用程序(而不是扩展)中工作,您必须配置libnotify的代理。[NTFNotify getInstance] setDelegate:<you implementation of protocol NTFNotifyDelegate>]

这允许您处理来自libnotify的一些消息,包括为用户打开主界面。我们可以从用户那里获取相应的请求,但我们无法预测您应用程序的结构。

特性

暗黑模式支持

Library Notify可以与暗黑模式一起工作。如果您的应用程序支持暗黑模式,您可以启用属性activitySettings.colorSettings.darkModeSupported。但请记住配置正确的颜色。

动态字体支持

库允许在活动配置中配置字体。您可以使用静态字体(默认),使用基于系统字体的动态字体,或者可以配置自定义字体。为此,您需要将属性activitySettings.fontType设置为自定义并在NotifyDelegate中实现几个方法。之后,库将要求您的应用程序提供字体。同时,库还会观察系统设置的变化,并在每次系统设置变化时请求适当的字体。

本地化

Libverify

如果您的应用程序支持更改语言,您可以通过设置属性 languageCode(使用 ISO 630-1 标准中定义的两字符代码)来配置 Libverify 的本地化。

LibverifyControls

您可以通过实现 NTFPhoneFormatterDelegateconfigureCountriesCodesViewController: 方法,并在 NTFPhoneCountriesCodesViewController 的实例中设置适当值至 controllerTitlesearchPlaceholder 属性来实现。此外,您还需要设置 NTFPhoneCountriesCodesViewControllercurrentLocale 属性以正确本地化国家名称和按钮“完成”。

技术笔记

模态接口

我们在 libnotify 中打开着陆界面,并在 libverify 中打开消息设置界面作为单独的窗口。这有助于我们呈现所需界面,同时节省主应用程序视图控制器堆栈。但有时我们可能会将我们的窗口设置为关键窗口。由于这种情况,如果您尝试使用 keyWindow 方法查找应用程序的主窗口,则可能会出现无效的行为。

注意

下一些建议将帮助您避免错误行为

  1. 尝试不要使用方法 [[UIApplication sharedApplication] keyWindow] 访问主窗口。详细内容请参阅上方技术说明。

需求

iOS 9.0

已知问题

  • (iOS 9.*): 活跃应用接收到的 APNS 推送将不被接受,库将发送包含值 Failed.REJECTED_IOS9_FOREGROUND 的事件 PushStatus。这是因为库不包含在应用程序内显示传入推送的工具。

许可

LGPL