Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Latest commit

 

History

History
60 lines (36 loc) · 1.81 KB

PUSH.md

File metadata and controls

60 lines (36 loc) · 1.81 KB

如何使用 AVOS Cloud 的 Push 功能

本文将向您简单介绍如何使用 AVOS Cloud 的推送功能。

登录到 Apple 的 Developer Program Portal

https://developer.apple.com/account/ios/certificate/certificateList.action

创建您的 App ID,并且选择允许 push。并且确保您的 App ID 不含有通配符

Apple Developer Program Portal

允许 App 的 Push 功能

Enable push

导出您的 Push 证书并且保存为 .p12 格式

Export push certification

请注意确保您的证书在导出时不带有密码保护

.p12 文件上传到 AVOS Cloud

upload push certification

使用您的 App ID 生成对应的 Provision Profile

dev profile

添加 Push 相关的代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    return YES;
}

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    AVInstallation *currentInstallation = [AVInstallation currentInstallation];
    [currentInstallation setDeviceTokenFromData:deviceToken];
    [currentInstallation saveInBackground];
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
    
    NSString *str = [NSString stringWithFormat: @"Error: %@", err];
    NSLog(@"Error %@", str);
}

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSLog(@"recevied %@", userInfo);
}