iOS 前台時的推送彈窗效果

來源:互聯網
上載者:User

標籤:

具體代碼:參看以下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    }}

 

     

iOS 前台時的推送彈窗效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.