iOS开发——极光推送

1.到极光官网 https://www.jpush.cn/ 下载极光推送SDK。

     具体如何集成最好参考官网的文档,以及一些失败的原因。文档非常详细,我也是参考集成的。

   2.到极光推送官网注册自己的应用信息,关键是参考官网文档把推送证书p12文件上传好。http://docs.jpush.io/client/ios_tutorials/#ios_1


3.将下载好的SDK解压的文件拖到项目中,并添加一下框架

  • CFNetwork.framework
  • CoreFoundation.framework
  • CoreTelephony.framework
  • SystemConfiguration.framework
  • CoreGraphics.framework
  • Foundation.framework
  • UIKit.framework
  • Security.framework
  • Xcode7需要的是libz.tbd;Xcode7以下版本是libz.dylib


4.可以参考我的其他博客,设置XCode7支持Http传输方法。

 

5.还需入下图配置下项目



6.在AppDelegate中,导入#import "JPUSHService.h"  

  建议在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中单独设置一个方法调用,防止和其他的设置混乱
    
    // 极光推送设置
    [self JPush:launchOptions];

 

7.以下是AppDelegate.m中主要需要实现的代码。包括设置AppKey

- (void)JPush:(NSDictionary *)launchOptions{
    
    // 程序未运行时,接收消息启动app
    NSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
    NSLog(@"未运行收到的消息%@",remoteNotification);

//#ifdef __IPHONE_8_0
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        //可以添加自定义categories
        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
                                                          UIUserNotificationTypeSound |
                                                          UIUserNotificationTypeAlert)
                                              categories:nil];
    } else {
        //categories 必须为nil
        [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                          UIRemoteNotificationTypeSound |
                                                          UIRemoteNotificationTypeAlert)
                                              categories:nil];
    }
    
//#endif
    // Required
    [JPUSHService setupWithOption:launchOptions appKey:@"ef7**********3d87" channel:@"Publish channel" apsForProduction:YES]; //如需兼容旧版本的方式,请继续使用[JPUSHService setupWithOption:launchOptions]初始化方法和添加pushConfig.plist文件声明AppKey等配置内容。
    
    
    // 开启调试模式debug
    [JPUSHService setDebugMode];
    
    
    //  接受自定义消息
    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
    [defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];
    NSNotificationCenter *defaultCenter1 = [NSNotificationCenter defaultCenter];
    [defaultCenter addObserver:self selector:@selector(JPushID:) name:kJPFNetworkDidLoginNotification object:nil];


}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
    // Required
    [JPUSHService registerDeviceToken:deviceToken];
    NSLog(@"注册的token%@",deviceToken);
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    
    //Optional
    NSLog(@"注册远程通知失败did Fail To Register For Remote Notifications With Error: %@", error);
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{

    NSLog(@"++++本地收到的消息====%@",notification);

}

// 应程序在前台或后台运行时接收消息
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    
     NSLog(@"获取到的APN推送内容: %@",userInfo);
    
    
    // IOS 7 Support Required
    [JPUSHService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
    
   
}


// 获取极光返回的用户ID
- (void)JPushID:(NSNotification *)notification{

    NSLog(@"获取到的registrationID===:%@",[JPUSHService registrationID]);

}

// 通知方法回调:接受自定义消息
- (void)networkDidReceiveMessage:(NSNotification *)notification {
    NSDictionary * userInfo = [notification userInfo];
    NSString *content = [userInfo valueForKey:@"content"];
    NSDictionary *extras = [userInfo valueForKey:@"extras"];
    NSString *customizeField1 = [extras valueForKey:@"customizeField1"]; //自定义参数,key是自己定义的
   // NSString *JPushID       = [];
 
    NSLog(@"接收自定义消息:%@",content);
    
   
    
    
}


8.这样可以单独在极光官网测试推送,最好单独获取到的registrationID单个推送测试。

  我开始可以内网推送,但走苹果APNS失败,最后还是推送证书的问题。重新做的并上传到极光推送逛网。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Clean Architectures in Python A practical approach to better software design By 作者: Leonardo Giordani Pub Date: 2019 ISBN: n/a Pages: 171 Language: English Format: PDF Size: 10 Mb The clean architecture is the opposite of spaghetti code, where everything is interlaced and there are no single elements that can be easily detached from the rest and replaced without the whole system collapsing. The main point of the clean architecture is to make clear “what is where and why”, and this should be your first concern while you design and implement a software system, whatever architecture or development methodology you want to follow. This book is divided into two parts. The first part is about Test-driven Development (TDD), a programming technique that will help you more reliable and easily modifiable software. I will first guide you through a very simple example in chapter 1, demonstrating how to use TDD to approach a project, and how to properly create tests from requirements. In chapter 2 I will then discuss unit testing from a more theoretical point of view, categorising functions and their tests. Chapter 3 will introduce mocks, a powerful tool that helps to test complex scenarios. The second part introduces the clean architecture. The first chapter discusses briefly the components and the ideas behind this software structure, while chapter 2 runs through a concrete example of clean architecture for a very simple web service. Chapter 3 discusses error management and improvements to the Python code developed in the previous chapter. Finally, chapter 4 shows how to plug different database systems to the web service created previously.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值