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
    }
}
相關文章
相關標籤/搜索