iOS远程消息推送自我整理版

@interface AppDelegate () <UIApplicationDelegate>

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

/************ 检测通知 **************/

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {

UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;

UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

} else {

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

}

return YES;

}

#pragma mark 消息推送模块

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken

{

// re-post ( broadcast )

NSString *token = [[[[deviceToken description]

stringByReplacingOccurrencesOfString:@"<" withString:@""]

stringByReplacingOccurrencesOfString:@">" withString:@""]

stringByReplacingOccurrencesOfString:@" " withString:@""];

NSString *oldToken=[[NSUserDefaults standardUserDefaults]objectForKey:@"Token"];

if (![token isEqualToString:oldToken]) {

[[NSUserDefaults standardUserDefaults]setObject:token forKey:@"Token"];

[[NSUserDefaults standardUserDefaults]synchronize];

}

//给后台发送Token

/*UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"token" message:token delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

alert.alertViewStyle = UIAlertViewStylePlainTextInput;

[alert textFieldAtIndex:0].text = token;

[alert show];*/

}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error

{

// re-post ( broadcast )

//[[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotificationError object:error];

NSLog(@">>>>注册远程推送失败<<<<");

}

//收到远程通知

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

{

if([UIApplication sharedApplication].applicationState == UIApplicationStateActive)

{

UILocalNotification *localNotification = [[UILocalNotification alloc] init];

localNotification.alertAction = @"Ok";

localNotification.userInfo = userInfo;

localNotification.soundName = UILocalNotificationDefaultSoundName;

localNotification.alertBody = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];

[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];

}

}

- (void)applicationWillResignActive:(UIApplication *)application {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}

- (void)applicationDidEnterBackground:(UIApplication *)application {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

- (void)applicationWillEnterForeground:(UIApplication *)application {

// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}

- (void)applicationDidBecomeActive:(UIApplication *)application {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

- (void)applicationWillTerminate:(UIApplication *)application {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

时间: 2024-10-25 22:07:45

iOS远程消息推送自我整理版的相关文章

iOS远程消息推送

iOS 推送基础知识 Apple 使用公共密钥数字证书对来自 iOS 应用程序的推送请求进行身份验证,所以您首先需要创建身份验证密钥,并向 Apple 注册它们.我将在下一节中花相当长的篇幅来直接介绍这一点. 接下来,需要确定安装该应用程序并选择接收该应用程序的推送通知的每台设备.工作顺序如下: iOS 应用程序中的一个警告对话框会请求用户的许可,以接收推送通知. 如果用户授予权限,iOS 应用程序会联系 Apple Push Notification 服务 (APNs) 获得一个 ID 字符串

iOS开发——远程消息推送的实现

在我们使用App的过程中.总是会收到非常多的消息推送.今天我们就要来实现这个功能.首先消息推送分为本地消息推送和远程消息推送.而当中又以远程消息最为经常使用. 可是在推送远程消息之前.有两个前提条件.你须要购买苹果的开发人员账号,也就是每年99刀:而且有一台iOS真机(模拟器不能測试推送).事实上远程推送须要有server,可是我们自己临时没有server,到时候后台使用Parse进行推送. 实现过程例如以下: (1)进入苹果的开发人员站点:https://developer.apple.com

iOS 细说消息推送

经常有同学问我们,iOS上推送究竟怎么做啊,为什么我的设备总收不到推送呢,这里跟大家集中讨论一下iOS上推送的实现细节. APNS的推送机制 与Android上我们自己实现的推送服务不一样,Apple对设备的控制非常严格,消息推送的流程必须要经过APNs: 这里 Provider 是指某个应用的Developer,当然如果开发者使用AVOS Cloud的服务,把发送消息的请求委托给我们,那么这里的Provider就是AVOS Cloud的推送服务程序了.上图可以分为三步: 第一步:AVOS Cl

iOS 10 消息推送(UserNotifications)秘籍总结(一)

背景 iOS10 新特性一出,各个大神就早已研究新特性能给场景智能化所带来的好处(唉,可惜我只是一个小白).我也被安排适配iOS10的推送工作! Apple 表示这是 iOS 有史以来最大的升级(our biggest release yet),更加智能开放的 Siri .强化应用对 3D Touch 支持. HomeKit .电话拦截及全新设计的通知等等… iOS 10 中将之前繁杂的推送通知统一成UserNotifications.framework 来集中管理和使用通知功能,还增加一些实用

IOS 之消息推送(个推)---个人小结

前言:自从上个星期开始整这个推送,弄了差不多一个星期,今天终于给整好了,因此现在来记录这段"奇妙"的旅程. 我们公司使用的消息推送是用的第三方--个推,这里不得不说一下,个推的技术人员还是蛮热心的,一直在帮助我排查问题,终于问题解决了,感谢感谢! 步骤及问题排查: 1.参照开发文档,集成SDK ,这里就不一一介绍了.(注意,个推的ios推送只能使用透传) 2.创建证书.苹果的推送证书分为开发证书(测试用)和生产证书(上线用).这里需要注意的就是,创建证书之前先必须打开证书的push 服

IOS本地消息推送(UILocalNotification)

IOS本地的Notification由iOS下NotificationManager统一管理,只需要将封装好的本地Notification对象加入到系统Notification管理机制队列中,系统会在指定的时间激发将本地Notification,应用只需设计好处理Notification的方法就完成了整个Notification流程了. IOS本地的Notification有UILocalNotification对象完成.它包括的主要属性有:fireDate.timeZone.repeatInt

玩转iOS开发 - 消息推送

消息推送 原文地址:https://www.cnblogs.com/zhchoutai/p/8550881.html

苹果iOS APNS消息推送通知

参考链接: http://www.tairan.com/archives/194 http://www.tairan.com/archives/240 https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ProvisioningDevelopment.html#//apple_ref/doc/uid/TP40008194

细说 iOS 消息推送

APNS的推送机制 与Android上我们自己实现的推送服务不一样,Apple对设备的控制很严格.消息推送的流程必需要经过APNs: 这里 Provider 是指某个应用的Developer,当然假设开发人员使用AVOS Cloud的服务,把发送消息的请求托付给我们,那么这里的Provider就是AVOS Cloud的推送服务程序了. 上图能够分为三步: 第一步:AVOS Cloud推送服务程序把要发送的消息.目的设备的唯一标识打包,发给APNs. 第二步:APNs在自身的已注冊Push服务的应