Skip to content

iOS Foreground Push Notification, the same as the system style, both Banner and Sound. 在 App 处于前台时展示跟系统完全一样的推送弹窗和声音。获取推送内容,并处理点击事件。

License

Notifications You must be signed in to change notification settings

Attiv/EBForeNotification

 
 

Repository files navigation

查看中文文档 Chinese README.md

Email:pikacode@qq.com

EBForeNotification

Show the Banners and Sounds as the same as the system notifications on foreground. Get notification content and Handle click event.

Support iOS 7~10 beta, support both simulator & iPhone build.

New Feature

  • swipe down gesture

  • iOS 10 banner style,example(iOS 10 style not support swipe down gesture and multi-line yet):

    [EBForeNotification handleRemoteNotification:userInfo soundID:soundID isIos10:YES];
    //or
    [EBForeNotification handleRemoteNotification:userInfo customSound:soundName isIos10:YES];

Display

  • The same UI with the system banner & sound
  • Auto get App name & App icon
  • Auto hide systm Status Bar and show
  • time & drag leg are the same color with current background
  • click gesture & handle it with notification info
  • swipe up gesture
  • swipe down gesture

Actual effect:

  • iOS 10 before style

  • iOS 10 style

Installation

pod

platform :ios, '7.0'

target 'YourTargetName' do
	pod 'EBForeNotification'
end

manual

Download and Drag EBForeNotification file folder into you Xcode project.

Native Banner

Call any 1 method below can show a banner on the frontest controller.

#import "EBForeNotification.h"
{...
//show a system sound banner
[EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":@"banner content"}} soundID:1312];

//show a cunstom sound banner
[EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":@"banner content"}} customSound:@"my_sound.wav"];

//show a system sound banner with extra keys/values
[EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":@"banner content"}, @"key1":@"value1", @"key2":@"value2"} soundID:1312];

//show a cunstom sound banner with extra keys/values
[EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":@"banner content"}, @"key1":@"value1", @"key2":@"value2"} customSound:@"my_sound.wav"];
...}

Handle Remote/Local Notification

Call the method in AppDelegate.m - didReceiveRemoteNotification , when received a notification, it will show a banner & sound on foreground automatically.

//AppDelegate.m
#import "EBForeNotification.h"

//ios7 before
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
	...
	//show a system sound banner
	[EBForeNotification handleRemoteNotification:userInfo soundID:1312];

	//show a cunstom sound banner
	[EBForeNotification handleRemoteNotification:userInfo customSound:@"my_sound.wav"];
    ...
}

//ios7 later  
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {    
	...
	//show a system sound banner
	[EBForeNotification handleRemoteNotification:userInfo soundID:1312];

	//show a cunstom sound banner
	[EBForeNotification handleRemoteNotification:userInfo customSound:@"my_sound.wav"];
    ...
    completionHandler(UIBackgroundFetchResultNewData);
}

Parma: soundID

  • Is iOS system sound id, default push notification sound "Tritone" is 1312

  • More sound id to see here iOS Predefined sounds or here AudioServices sounds

  • You can download all the system sounds UISounds.zip , listen and choose one which you perfer, then check out it's id with the form above

Handle Click

Add observer for EBBannerViewDidClick, get extra key/value to handle your custom events, such as: jump to some page when user clicked.

Received notification:

{
    "aps":
    {
        "alert":"content",
        "sound":"sound",
        "badge":"3"
    },
        "key1":"jump1"  //customed like this to jump
}

Add observer:

#import "EBForeNotification.h"

{...
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eBBannerViewDidClick:) name:EBBannerViewDidClick object:nil];
...}

-(void)eBBannerViewDidClick:(NSNotification*)noti{
    if(noti[@"key1" == @"jump1"]){
        //jump to page 1
    }
}

About

iOS Foreground Push Notification, the same as the system style, both Banner and Sound. 在 App 处于前台时展示跟系统完全一样的推送弹窗和声音。获取推送内容,并处理点击事件。

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 88.9%
  • Ruby 11.1%