测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | 自定义 |
发布最新发布 | 2015年9月 |
由Illya Busigin,Sam Odom,Illya Busigin,Xiangwei Wang,Steven Spry维护。
版本 1.4.0
这是 Phunware 的 iOS SDK,用于 Alerts & Notifications 模块。访问 http://maas.phunware.com/ 获取更多详情并注册。
推荐使用 CocoaPods 来使用 PWAlerts。要将 PWAlerts 添加到您的 Podfile
,请添加以下 pod
pod 'PWAlerts', '~>1.3.0'
PWAlerts 依赖于 PWCore.framework,可在以下位置找到:https://github.com/phunware/maas-core-ios-sdk
建议将 MaaS 框架添加到 'Vendor/Phunware' 目录。然后,将 PWCore.framework 和 PWAlerts.framework 添加到您的 Xcode 项目中。
以下是需要以下项目
PWCore.framework
滚动查看实现细节。
PWAlerts 文档包含在仓库中的 Documents 文件夹中,既以 HTML 格式也存在 .docset 格式。您还可以在此找到最新文档:http://phunware.github.io/maas-alerts-ios-sdk/
以下是一些资源,可帮助您为 Apple Push Notifications 配置您的应用程序
在您的应用程序代理 (.m) 文件顶部,添加以下内容
#import <PWCore/PWCore.h>
#import <PWAlerts/PWAlerts.h>
在您的应用程序代表中,您需要在 application:didFinishLaunchingWithOptions: 方法中初始化 PWCore。有关 PWCore 安装指南的更多详细信息,请参阅:https://github.com/phunware/maas-core-ios-sdk#installation
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// These values can be found for your application in the MaaS portal.
[PWCore setApplicationID:@"APPLICATION_ID"
setAccessKey:@"ACCESS_KEY"
signatureKey:@"SIGNATURE_KEY"
encryptionKey:@"ENCRYPT_KEY"]; // Currently unused. You can place any NSString value here.
...
}
截至 PWAlerts v1.3.1,应用程序开发者负责向 Apple 注册远程通知。以下代码(或类似代码)应出现在应用程序代理或开发者在注册远程通知时的代码中
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
}
else {
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert];
}
Apple 有三种主要的处理远程通知的方法。您需要在您的应用程序代理中实现这些方法,并将结果转发到 PWAlerts
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
{
[PWAlerts didRegisterForRemoteNotificationsWithDeviceToken:devToken];
...
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
[PWAlerts didFailToRegisterForRemoteNotificationsWithError:err];
...
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[PWAlerts didReceiveRemoteNotification:userInfo];
...
}
有关完整示例,请参阅 https://github.com/phunware/maas-alerts-ios-sdk/tree/master/Sample
MaaS门户提供设置过滤警报和通知的警报段功能。这通过两个PWAlerts SDK方法来支持:getAlertSegmentsWithSuccess:failure: 和 updateAlertSegments:success:failure:。
// Fetch an array of the available subscriptions.
[PWAlerts getAlertSegmentsWithSuccess:^(NSArray *segments) {
// Display the available alert segments to the user.
// The segments array will contain PWAlertSegment objects.
} failure:^(NSError *error) {
// Handle error.
}];
// To update the alert segments, make the following call:
NSArray *alertSegments = @[segmentOne, segmentFour, ...];
[PWAlerts updateAlertSegments:alertSegments success:^{
// Handle success.
} failure:^(NSError *error) {
// Handle error.
}];
}
警报段通过PWAlertSegment对象表示。这些对象有一个名称(NSString)、一个标识符(NSString)、一个订阅标志和一个子段数组。在更新警报段订阅时,应根据需要在每个段上设置或清除订阅标志。未传递的段被视为未订阅。开发者不再需要维护订阅的警报段列表,因为SDK现在自动完成此任务。
注意:请使用上述新方法来管理警报段,因为以下方法已被弃用
使用PWAlerts获取与推送通知相关的元数据可以通过以下方法实现:getExtraInformationForAlert:success:failure:
// When receiving a notification, you can save save the data in a PWAlert object.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[PWAlerts didReceiveRemoteNotification:userInfo];
PWAlert *alert = [PWAlert alloc] initWithNotificationUserInfo:userInfo];
...
}
// Pass the PWAlert object to retrieve extra information.
[PWAlerts getExtraInformationForAlert:alert success:^(NSDictionary *extraInformation) {
// Process the extra information.
} failure:^(NSError *error) {
// Handle error.
}];