AeroGear-Push 1.2.0

AeroGear-Push 1.2.0

测试已测试
语言语言 Obj-CObjective C
许可证 Apache 2
发布最后发布2017年10月

由以下人员维护:corinne krychJulio CesarDaniel PassosMassimiliano Ziccardi



  • Red Hat, Inc.

aerogear-ios-push Build Status

AeroGear 统一推送服务器的 iOS 推送通知注册 SDK

这是一个小巧且实用的库,帮助 iOS 应用程序注册到 AeroGear 统一推送服务器

项目信息
许可证 Apache 许可证,版本 2.0
构建 CocoaPods
文档 http://aerogear.org/ios/
问题跟踪器 https://issues.jboss.org/browse/AGIOS
邮件列表 aerogear-users (订阅)
aerogear-dev (订阅)

构建库

要构建库,只需运行构建脚本

build.sh

构建脚本将生成一个包含通用静态库和框架的 buid 文件夹,源代码和文档也被打包。

push-sdk.xcodeproject 包含两个框架目标 pushsdk,以构建从 iOS8 支持的动态框架,当运行单元测试时使用,以及 push-sdk,用于构建从 iOS7 支持的静态框架。

注意 动态框架名称不应包含 - 符号。

将库添加到您的项目

您有多种方法可以将 aerogear-push-registration 库添加到您的项目中。

方法 2:使用静态库

  • 步骤 1:复制库

在构建库(请参阅“构建库”部分)后,从 aerogear-ios-push 目录运行复制命令

cp -R build/AeroGearPush-iphoneuniversal/* ../<YourProjectFolder>
  • 步骤 2:头文件搜索

转到项目导航器中的根节点,选择目标。选择构建设置,在列表中定位到头文件搜索路径设置。双击头文件搜索路径项,将弹出一个窗口。单击 + 按钮,输入以下内容

$SOURCE_ROOT/include
  • 步骤 3:添加库

选择构建阶段选项卡,展开链接二进制文件与库部分,并添加 libpush-sdk-X.X.X.a

  • 步骤 4:添加链接器标志

单击构建设置选项卡,定位到其他链接器标志设置,并添加 -ObjC

注意:请参阅上面的 64 位注意事项。

方法 3:使用框架

  • 步骤 1:复制框架

构建框架(请参阅“构建库”部分)后,从 aerogear-ios-push 目录运行复制命令

cp -R build/AeroGearPush-framework/AeroGearPush.framework ../<YourProjectFolder>
  • 步骤 2:将框架添加到构建阶段

前往目标。在构建阶段/链接二进制与库中添加AeroGearPush.framework

  • 第3步:默认导入的尖括号
#import <AeroGearPush/AeroGearPush.h>

您可以使用aerogear-push-helloworld作为使用aerogear-push-ios-registration作为框架依赖的项目示例。

注意:请参阅上面的 64 位注意事项。

示例用法

推送注册

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

  AGDeviceRegistration *registration = 
    [[AGDeviceRegistration alloc] initWithServerURL:
	   [NSURL URLWithString:@"http://YOUR_SERVER/ag-push/"]];

  [registration registerWithClientInfo:^(id<AGClientDeviceInformation> clientInfo) {

    [clientInfo setDeviceToken:deviceToken];
    [clientInfo setVariantID:@"YOUR IOS VARIANT ID"];
    [clientInfo setVariantSecret:@"YOUR IOS VARIANT SECRET"];

    // --optional config--
    UIDevice *currentDevice = [UIDevice currentDevice];
    [clientInfo setOperatingSystem:[currentDevice systemName]];
    [clientInfo setOsVersion:[currentDevice systemVersion]];
    [clientInfo setDeviceType: [currentDevice model]];
	} success:^() {
      NSLog(@"UnifiedPush Server registration worked");
	} failure:^(NSError *error) {
      NSLog(@"UnifiedPush Server registration Error: %@", error);
  }];
}

带有app plist的推送注册

ppDelegate.m文件中

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

  AGDeviceRegistration *registration = 
    [[AGDeviceRegistration alloc] init];

  [registration registerWithClientInfo:^(id<AGClientDeviceInformation> clientInfo) {

    [clientInfo setDeviceToken:deviceToken];
    UIDevice *currentDevice = [UIDevice currentDevice];
    [clientInfo setOperatingSystem:[currentDevice systemName]];
    [clientInfo setOsVersion:[currentDevice systemVersion]];
    [clientInfo setDeviceType: [currentDevice model]];
  } success:^() {
      NSLog(@"UnifiedPush Server registration worked");
  } failure:^(NSError *error) {
      NSLog(@"UnifiedPush Server registration Error: %@", error);
  }];
}

在您的应用程序info.plist中添加以下属性

<plist version="1.0">
<dict>
  <key>serverURL</key>
  <string><# URL of the running AeroGear UnifiedPush Server #></string>
  <key>variantID</key>
  <string><# Variant Id #></string>
  <key>variantSecret</key>
  <string><# Variant Secret #></string>
</dict>
</plist>

注意:如果您的UPS服务器安装使用的是自签名证书,您可以在我们的故障排除页面中找到快速解决办法,以及有关如何正确在您的iOS生产应用程序中启用它的更多信息链接。

接收远程通知

使用AeroGear库接收通知时没有额外的钩子。您可以在应用程序运行时使用现有的代理来接收远程通知,例如

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  // extract desired value from the dictionary...
}

推送分析

如果您对监测推送消息如何与您的应用使用情况相关感兴趣,可以使用指标。这些指标在AeroGear统一推送服务器的控制台中显示。

  • 当应用程序由于推送通知而启动时发送指标
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [AGPushAnalytics sendMetricsWhenAppLaunched:launchOptions];
    return YES;
}
  • 应用程序因推送通知从后台带到前台时发送指标
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {    
    [AGPushAnalytics sendMetricsWhenAppAwoken:application.applicationState userInfo: userInfo];
}

AeroGear统一推送服务器

更多信息,请参阅我们的教程

文档

有关当前版本更详细的信息,请参阅我们的文档

开发

如果您想帮助开发AeroGear,您可以加入我们的开发者邮件列表,加入Freenode上的#aerogear,或在Twitter @aerogears上向我们发话。

还要花点时间阅读贡献指南

有疑问吗?

加入我们的用户邮件列表,以便提出任何疑问或寻求帮助!我们真的希望您享受使用AeroGear进行应用程序开发!

发现虫子了吗?

如果您发现了虫子,请在我们Jira上为我们创建一个票据,并提供一些重现步骤。