Code Monkey home page Code Monkey logo

ebforenotification's Introduction

查看中文文档 Chinese README.md

Email:[email protected]

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
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.