iOS 前台时的推送弹窗效果

具体代码:参看如下demophp

Github: https://github.com/Yasashi/EBForeNotificationios

具体操做以下:git

   一、将EBForeNotification文件夹添加进入工程中github

   二、targets --> Build Settings --> 搜 other link --> 添加 -ObjCapp

   三、本地弹窗iphone

        

//普通弹窗(系统声音)
[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"];
...}

      四、接受远程、本地推送弹窗fetch

 

//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);
}

              注明:soundID 参数:iOS 系统自带的声音 id,系统级的推送服务默认使用的是三全音,id = 1312,其余系统声音 id 能够在这里查询到 iOS Predefined sounds备用地址 AudioServices soundsui

              五、添加 Observer 监听 EBBannerViewDidClick,获取推送内容,经过推送时自定义的字段处理本身逻辑,如:跳转到对应页面等。.net

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eBBannerViewDidClick:) name:EBBannerViewDidClick object:nil];
-(void)eBBannerViewDidClick:(NSNotification*)noti{
    if(noti[@"key1" == @"跳转页面1"]){
        //跳转到页面1
    }
}
相关文章
相关标签/搜索