iOS 前台時的推送彈窗效果


具體代碼:參看以下demo

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

具體操作如下:

   1、將EBForeNotification文件夾添加進入工程中

   2、targets --> Build Settings --> 搜 other link --> 添加 -ObjC

   3、本地彈窗

        

//普通彈窗(系統聲音)
[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"];
...}

      4、接受遠程、本地推送彈窗

 

//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 sounds

              5、添加 Observer 監聽 EBBannerViewDidClick,獲取推送內容,通過推送時自定義的字段處理自己邏輯,如:跳轉到對應頁面等。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eBBannerViewDidClick:) name:EBBannerViewDidClick object:nil];
-(void)eBBannerViewDidClick:(NSNotification*)noti{
    if(noti[@"key1" == @"跳轉頁面1"]){
        //跳轉到頁面1
    }
}

 

     


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM