CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.
TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Oct 2017 |
Maintained by pikacode, pikacode.
Looking for English README.md
QQ: 57380422
在 App 处于前台时展示跟系统完全一样的推送弹窗
和声音
。获取推送内容,并且处理点击事件。
支持 iOS 7~10 beta,支持模拟器
和真机
运行。
iOS 10 弹窗样式,调用方法 (iOS 10 样式暂不支持下滑手势
和多行内容
)
[EBForeNotification handleRemoteNotification:userInfo soundID:soundID isIos10:YES];
}
[EBForeNotification handleRemoteNotification:userInfo customSound:soundName isIos10:YES];
应用名称
,应用图标
时间
及下方收拉条
的颜色跟当前页面的背景颜色相同点击事件
,点击可获取推送内容,进行相应页面跳转上滑手势
,快速收起下滑手势
,展开消息完整内容实际效果如下:
platform :ios, '7.0'
target 'YourTargetName' do
pod 'EBForeNotification'
end
下载并在 Xcode 中
拖拽拷贝
根目录中的 EBForeNotification
文件夹至 Xcode 工程。
在任意方法内调用以下任 1 行代码即可弹窗
#import "EBForeNotification.h"
{...
//普通弹窗(系统声音)
[EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":@"展示内容"}} soundID:1312];
//普通弹窗(指定声音文件)
[EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":@"展示内容"}} customSound:@"my_sound.wav"];
//带自定义参数的弹窗(系统声音)
[EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":@"展示内容"}, @"key1":@"value1", @"key2":@"value2"} soundID:1312];
//带自定义参数的弹窗(指定声音文件)
[EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":@"展示内容"}, @"key1":@"value1", @"key2":@"value2"} customSound:@"my_sound.wav"];
...}
接收远程/本地推送后,自动在前台展示推送弹窗及声音。
在 AppDelegate.m
中添加代码
//AppDelegate.m
#import "EBForeNotification.h"
//ios7 before
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
...
//系统声音弹窗
[EBForeNotification handleRemoteNotification:userInfo soundID:1312];
//指定声音文件弹窗
[EBForeNotification handleRemoteNotification:userInfo customSound:@"my_sound.wav"];
...
}
//ios7 later
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
...
//系统声音弹窗
[EBForeNotification handleRemoteNotification:userInfo soundID:1312];
//指定声音文件弹窗
[EBForeNotification handleRemoteNotification:userInfo customSound:@"my_sound.wav"];
...
completionHandler(UIBackgroundFetchResultNewData);
}
iOS 系统自带的声音 id,系统级的推送服务默认使用的是三全音
,id = 1312
其他系统声音 id 可以在这里查询到 iOS Predefined sounds 备用地址 AudioServices sounds
添加 Observer
监听 EBBannerViewDidClick
,获取推送内容,通过推送时自定义的字段处理自己逻辑,如:跳转到对应页面等。
接收到的推送内容类似以下:
{
"aps":
{
"alert":"推送内容",
"sound":"sound",
"badge":"3"
},
"key1":"跳转页面1" //自定义此字段以跳转到相应页面
}
添加 Observer
获取自定义的字段,并处理:
#import "EBForeNotification.h"
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eBBannerViewDidClick:) name:EBBannerViewDidClick object:nil];
-(void)eBBannerViewDidClick:(NSNotification*)noti{
if(noti[@"key1" == @"跳转页面1"]){
//跳转到页面1
}
}