ZeroPush 2.1.2

ZeroPush 2.1.2

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最新发布2016年4月

Stefan NatchevAdam Duke 维护。



ZeroPush 2.1.2

  • Adam Duke 和 Stefan Natchev

目的

ZeroPush-iOS 是围绕 ZeroPush API 的轻量级 Objective C 封装。它提供了一些方便的方法,帮助您尽可能快地使用 ZeroPush。

构建/链接/添加到您的项目

我们建议使用 ZeroPush Cocoapod

在您的 Podfile 中添加以下行

pod 'ZeroPush', '~> 2.0'

并安装 Pods

$> pod install

配置

客户端库安装后,在您的 AppDelegate 中添加以下内容。

//In AppDelegate.h - Add the ZeroPushDelegate

#import "ZeroPush.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate, ZeroPushDelegate>


// In AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

#if DEBUG
    [ZeroPush engageWithAPIKey:@"iosdev_apptoken" delegate:self];
#else
    [ZeroPush engageWithAPIKey:@"iosprod_apptoken" delegate:self];
#endif

    //now ask the user if they want to recieve push notifications. You can place this in another part of your app.
    [[ZeroPush shared] registerForRemoteNotifications];

    return true;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)tokenData
{
    // Call the convenience method registerDeviceToken, this helps us track device tokens for you
    [[ZeroPush shared] registerDeviceToken:tokenData];

    // This would be a good time to save the token and associate it with a user that you want to notify later.
    NSString *tokenString = [ZeroPush deviceTokenFromData:tokenData];
    NSLog(@"%@", tokenString);

    // For instance you can associate it with a user's email address
    // [[ZeroPush shared] subscribeToChannel:@"[email protected]"];
    // You can then use the /broadcast endpoint to notify all devices subscribed to that email address. No need to save tokens!
    // Don't forget to unsubscribe from the channel when the user logs out of your app!
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    NSLog(@"%@", [error description]);
    //Common reason for errors:
    //  1.) Simulator does not support receiving push notifications
    //  2.) User rejected push alert
    //  3.) "no valid 'aps-environment' entitlement string found for application"
    //      This means your provisioning profile does not have Push Notifications configured. https://zeropush.com/documentation/generating_certificates
}

从 iOS7 升级

如果您在 iOS7 中使用了辅助方法 [[ZeroPush shared] registerForRemoteNotificationTypes:],则在部署到 iOS8 时需要更改

之前

[[ZeroPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

之后

[[ZeroPush shared] registerForRemoteNotifications];

文档

有关更详细的文档,请参阅 ZeroPush Docs.

许可证

版权所有(c)2015 Symmetric Infinity LLC

MIT 许可证

本许可证授予任何获得此软件及其相关文档副本(以下简称“软件”)的人员,无权在任何形式下使用、复制、修改、合并、发布、分发、再许可、销售软件副本,并允许将软件提供给他人使用,以执行上述操作,前提是满足以下条件

以上版权声明和本许可声明应包含在软件的所有副本或主要部分之中。

软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、适用于特定目的和侵犯知识产权方面的保证。在任何情况下,作者或版权持有者都不应对任何索赔、损害或其他责任负责,无论源于合同、侵权或其他原因,包括但在不限于软件或其使用或操作的后果。