本地推送的实现

本地推送(主要用于耗时操作,当操作完成之后可以通知给用户)

步骤如下:

1.在app delegate  didFinishLaunchingWithOptions方法中进行推送设置

推送设置(iOS8.0以后设置方法发生改变)

//版本适配问题

if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0)//当前使用设备

{

//采取8.0以上的设置

/**

*  @param UIUserNotificationType 推动通知的类型(声音/文字/标示(徽章))

*  @param categories 额外设置(设置额外按钮)

*/

UIUserNotificationSettings * settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil];

//让当前程序接收/注册推送通知设置

[application registerUserNotificationSettings:settings];

//询问用户是否允许

[application registerForRemoteNotifications];

}

2.开始推送

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

if (noti) {

//设置推送通知

//通知推送事件

//开启事件为当前时间后10秒

noti.fireDate = [[NSDate date] dateByAddingTimeInterval:10];

//重复次数

//不重复

noti.repeatInterval = 0;

//设置推送时区

noti.timeZone = [NSTimeZone defaultTimeZone];

//增加图标标示

noti.applicationIconBadgeNumber = 1;

//设置推送声音 音频声音格式要为苹果原生支持的

noti.soundName = UILocalNotificationDefaultSoundName;

//推送内容

noti.alertBody = @"ajdfjkjljhb";

//设置推送的携带详情,例如为某影片播放网址

noti.userInfo = @{@"URL":@""};

//执行推送

[[UIApplication sharedApplication] scheduleLocalNotification:noti];

}

注:通过推送进入App时会调用的方法

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

{

NSLog(@"通过推送进入APP");

NSDictionary * us = notification.userInfo;

NSLog(@"URL为:%@",us[@"URL"]);

//执行跳转

[self.window.rootViewController presentViewController:[[PlayViewController alloc]init] animated:YES completion:nil];

}


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 推送通知 注意:这里说的推送通知跟NSNotification有所区别 NSNotification是抽象的,不可...
    iOS开发攻城狮阅读 4,346评论 1 13
  • 概述 在多数移动应用中任何时候都只能有一个应用程序处于活跃状态,如果其他应用此刻发生了一些用户感兴趣的那么通过通知...
    莫离_焱阅读 6,580评论 1 8
  • 极光推送: 1.JPush当前版本是1.8.2,其SDK的开发除了正常的功能完善和扩展外也紧随苹果官方的步伐,SD...
    Isspace阅读 6,800评论 10 16
  • 推送通知注意:这里说的推送通知跟NSNotification有所区别NSNotification是抽象的,不可见的...
    醉叶惜秋阅读 1,552评论 0 3
  • 在简单项目中,有使用到apns推送服务,许多文章有涉及到却没有讲清楚。最近做福路通项目,有使用到,做一个总结。 推...
    天空的守望者阅读 917评论 0 3