XGPush集成(信鸽集成)demo

  1 #import "AppDelegate.h"
  2 #import "XGPush.h"
  3 #import "XGSetting.h"
  4
  5 #define _IPHONE80_ 80000
  6
  7 @implementation AppDelegate
  8 - (void)registerPushForIOS8{
  9 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_
 10
 11     //Types
 12     UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
 13
 14     //Actions
 15     UIMutableUserNotificationAction *acceptAction = [[UIMutableUserNotificationAction alloc] init];
 16
 17     acceptAction.identifier = @"ACCEPT_IDENTIFIER";
 18     acceptAction.title = @"Accept";
 19
 20     acceptAction.activationMode = UIUserNotificationActivationModeForeground;
 21     acceptAction.destructive = NO;
 22     acceptAction.authenticationRequired = NO;
 23
 24     //Categories
 25     UIMutableUserNotificationCategory *inviteCategory = [[UIMutableUserNotificationCategory alloc] init];
 26
 27     inviteCategory.identifier = @"INVITE_CATEGORY";
 28
 29     [inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextDefault];
 30
 31     [inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextMinimal];
 32
 33     NSSet *categories = [NSSet setWithObjects:inviteCategory, nil];
 34
 35
 36     UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:categories];
 37
 38     [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
 39
 40
 41     [[UIApplication sharedApplication] registerForRemoteNotifications];
 42 #endif
 43 }
 44
 45 - (void)registerPush{
 46     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
 47 }
 48
 49
 50 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 51 {
 52     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
 53
 54     //注册推送
 55      [XGPush startApp:2200065428 appKey:@"IXJ8177VC3BG"];
 56
 57     //注销之后需要再次注册前的准备
 58     void (^successCallback)(void) = ^(void){
 59         //如果变成需要注册状态
 60         if(![XGPush isUnRegisterStatus])
 61         {
 62             //iOS8注册push方法
 63 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_
 64
 65             float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue];
 66             if(sysVer < 8){
 67                 [self registerPush];
 68             }
 69             else{
 70                 [self registerPushForIOS8];
 71             }
 72             NSLog(@"sysVer ----------- %g", sysVer);
 73 #else
 74             //iOS8之前注册push方法
 75             //注册Push服务,注册后才能收到推送
 76             [self registerPush];
 77 #endif
 78         }
 79     };
 80     [XGPush initForReregister:successCallback];
 81
 82     //推送反馈回调版本示例
 83     void (^successBlock)(void) = ^(void){
 84         //成功之后的处理
 85         NSLog(@"[XGPush]handleLaunching‘s successBlock");
 86     };
 87
 88     void (^errorBlock)(void) = ^(void){
 89         //失败之后的处理
 90         NSLog(@"[XGPush]handleLaunching‘s errorBlock");
 91     };
 92     [XGPush handleLaunching:launchOptions successCallback:successBlock errorCallback:errorBlock];
 93     //角标清0
 94     [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
 95
 96     //清除所有通知(包含本地通知)
 97     [XGPush clearLocalNotifications];
 98     //本地推送示例
 99 //    [XGPush handleLaunching:launchOptions successCallback:successBlock errorCallback:errorBlock];
100 //
101 //    NSDate *fireDate = [[NSDate new] dateByAddingTimeInterval:5];
102 //
103 //    NSMutableDictionary *dicUserInfo = [[NSMutableDictionary alloc] init];
104 //    [dicUserInfo setValue:@"myid" forKey:@"clockID"];
105 //    NSDictionary *userInfo = dicUserInfo;
106 //
107 //    [XGPush localNotification:fireDate alertBody:@"测试本地推送" badge:2 alertAction:@"确定" userInfo:userInfo];
108    [self.window makeKeyAndVisible];
109     return YES;
110 }
111 #pragma mark - Notification
112
113 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_
114
115 //注册UserNotification成功的回调
116 - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
117 {
118     //用户已经允许接收以下类型的推送
119     //UIUserNotificationType allowedTypes = [notificationSettings types];
120     NSLog(@"didRegisterUserNotificationSettings");
121 }
122
123 //按钮点击事件回调
124 - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler{
125     if([identifier isEqualToString:@"ACCEPT_IDENTIFIER"]){
126         NSLog(@"ACCEPT_IDENTIFIER is clicked");
127     }
128
129     completionHandler();
130 }
131
132 #endif
133
134 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
135
136     NSLog(@"Token----------------: %@", [[NSString alloc] initWithData:deviceToken encoding:NSUTF8StringEncoding]);
137
138     NSString * deviceTokenStr = [XGPush registerDevice:deviceToken];
139
140     //注册设备
141     [XGPush setAccount:@"123456"];
142 //    [XGPush registerDevice:deviceToken];
143
144     void (^successBlock)(void) = ^(void){
145         //成功之后的处理
146         NSLog(@"[XGPush]register successBlock ,deviceToken: %@",deviceTokenStr);
147     };
148
149     void (^errorBlock)(void) = ^(void){
150         //失败之后的处理
151         NSLog(@"[XGPush]register errorBlock");
152     };
153
154     [XGPush registerDevice:deviceToken successCallback:successBlock errorCallback:errorBlock];
155
156     //打印获取的deviceToken的字符串
157     NSLog(@"deviceTokenStr is %@",deviceTokenStr);
158 }
159
160 //如果deviceToken获取不到会进入此事件
161 - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
162
163     NSString *str = [NSString stringWithFormat: @"Error: %@",err];
164
165     NSLog(@"%@",str);
166
167 }
168
169 - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
170 {// 取得 APNs 标准信息内容
171     NSDictionary *aps = [userInfo valueForKey:@"aps"];
172     NSString *content = [aps valueForKey:@"alert"]; //推送显示的内容
173     NSInteger badge = [[aps valueForKey:@"badge"] integerValue]; //badge数量
174     //    badge += [UIApplication sharedApplication].applicationIconBadgeNumber;
175
176     NSLog(@"didReceiveRemoteNotification badge = %ld, systemBadgeNumber = %ld", (long)badge, (long)[UIApplication sharedApplication].applicationIconBadgeNumber);
177     //    [APService setBadge:badge];
178     NSLog(@"data:%@ --- dic:%@", aps, userInfo);
179
180     [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
181     //    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge];
182     NSString *sound = [aps valueForKey:@"sound"]; //播放的声音
183
184     // 取得自定义字段内容
185     NSString *customizeField1 = [userInfo valueForKey:@"customizeField1"]; //自定义参数,key是自己定义的
186     NSLog(@"content =[%@], badge=[%ld], sound=[%@], customize field =[%@]",content,(long)badge,sound,customizeField1);
187     //推送反馈(app运行时)
188     [XGPush handleReceiveNotification:userInfo];
189
190
191 }
192
193 -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
194     //notification是发送推送时传入的字典信息
195     [XGPush localNotificationAtFrontEnd:notification userInfoKey:@"clockID" userInfoValue:@"myid"];
196
197     //删除推送列表中的这一条
198 //    [XGPush delLocalNotification:notification];
199     //[XGPush delLocalNotification:@"clockID" userInfoValue:@"myid"];
200
201     //清空推送列表
202     //[XGPush clearLocalNotifications];
203 }
204
205
206 @end
时间: 2024-10-12 20:59:48

XGPush集成(信鸽集成)demo的相关文章

QtAndroid详解(6):集成信鸽推送

推送是我们开发移动应用经常用到的功能,Qt on Android 应用也会用到,之前也有朋友问过,这次我们来看看怎么在 Qt on Android 应用中来集成来自腾讯的信鸽推送. 有关信鸽的 SDK 和集成指南,请到这里(http://xg.qq.com/)查看.本文是参考腾讯信鸽的在线帮助完成的.信鸽的 WIKI 和文档已经做得很好了,照着做就是,这里只讲 Qt 中集成信鸽时的步骤和注意事项. 这次我们要写一点点 Java 代码,就几行,如何做,可以参考<Qt on Android核心编程>

.Net集成PayPal的Demo

近来项目中需要使用Paypal(贝宝)支付,研究了一下接口,真是吐血,花了一个下午+一个晚上,屡败屡战,海淘了若干文档,终于尝试成功了,分享一下,希望对将要使用paypal的朋友有所帮助. paypal提供3种类型的对外付款接口,可参考:https://cms.paypal.com/c2/cgi-bin/?cmd=_render-content&content_ID=pages_c2/profile_comparison_new&fli=true 我们这里采用标准的网页版本,其中标准的网页

BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第11章节--为Office和SP解决方案开发集成Apps 集成SP和Office App

BEGINNING SHAREPOINT? 2013 DEVELOPMENT 第11章节--为Office和SP解决方案开发集成Apps  集成SP和Office App 你可以用两种方法将Office Apps和SP集成.

XGPush集成(信鸽集成)

1 1 #import "AppDelegate.h" 2 2 #import "XGPush.h" 3 3 #import "XGSetting.h" 4 4 5 5 #define _IPHONE80_ 80000 6 6 7 7 @implementation AppDelegate 8 8 - (void)registerPushForIOS8{ 9 9 #if __IPHONE_OS_VERSION_MAX_ALLOWED >=

android app 集成 信鸽推送

推送其实挺中意小米推送的,并经用户群占比还是比较大的,奈何拗不过php后端哥们的选型,就只好用信鸽推送了,期间接入过程中也是遇到不少问题,所以记录下来,以后如果还是用信鸽推送的话,估计看看以前的博客,也能少踩点坑. 因为最新版本是2.43,所以按照2.43的引入为准 1,导入jar包和so文件: 文件夹为信鸽推送必须的so文件: 2,针对so文件,gradle文件进行配置,生成第一张图里面的native_libs2的jar文件: 3,AndroidManifest.xml文件的配置,这个基本按照

移动推送 腾讯信鸽集成

背景 现在移动推送很多大厂都在做,腾讯信鸽跟个推.极光.友盟比算是比较晚的一个了. 但这并不妨碍我用它. 服务端 这边服务端用的C#,有两种方式集成腾讯信鸽: 1.引用官方编译好的XingeApp.dll 推荐,相当简单方便,基本的Api都有. ps:老版本的NewtonsoftJson(低于10.0.0)可能会报错. 2.调用Restful Api 不谈,稍微麻烦了些. Android端 推荐使用Android Studio一键引用.就很方便了.(基于AS 3.0.1) build.gradl

JAVA应用程序单独集成Mybatis使用Demo

参考博客:http://www.cnblogs.com/magialmoon/archive/2013/10/30/3397828.html 整体结构 POM依赖 <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.2.3</version> </dependency> <depen

支付宝集成的小坑--集成支付宝集成总结(1)

现在很多公司的APP都会有支付环节,特别是现在的O2O项目,我参与过的近两个项目都有集成支付宝对两次集成做一下总结: 第一次集成支付宝,由于我们的做后台的大牛写了十几年代码,而且以前是银行项目的总监,整个支付流程基本上一切听大牛的,我按照做就行.基本上按照支付宝的流程走,支付环节没怎么出问题,总体来说支付流程比较perfect. 第一次集成的小坑: 1)无非就是支付宝里面使用了一些框架如SBJson 等常用的开源框架,而我们项目中也会用到SBJson类似的框架,估计会出现冲突 冲突的解决办法:A

CKEditor 集成CKFinder集成

lCKEditor原名FckEditor,著名的HTML编辑器,可以在线编辑HTML内容,演示一下.打开.自己人用CKEditor,网友用UBBEditor. l配置参考文档,主要将ckeditor中的(adapters.images.lang.plugins.skins.themes.ckeditor.js.config.js.contents.css)解压到js目录,然后“显示所有文件”,将ckeditor的目录“包含在项目中”,在发帖页面引用ckeditor.js,然后设置多行文本框的cl