Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
pikacode committed Jul 27, 2016
2 parents 590cc55 + eff13a0 commit 871cfd0
Show file tree
Hide file tree
Showing 46 changed files with 2,825 additions and 2 deletions.
141 changes: 141 additions & 0 deletions EBForeNotification.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#
# Be sure to run `pod spec lint EBForeNotification.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |s|

# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# These will help people to find your library, and whilst it
# can feel like a chore to fill in it's definitely to your advantage. The
# summary should be tweet-length, and the description more in depth.
#

s.name = "EBForeNotification"
s.version = "1.1.0"
s.summary = "iOS 前台推送及事件处理。iOS Foreground Push Notification and event-handle."

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
在 App 处于前台时展示跟系统完全一样的推送弹窗和声音。获取推送内容,并处理点击事件。iOS Foreground Push Notification, the same as the system style, both Banner and Sound.
DESC

s.homepage = "https://github.com/Yasashi/EBForeNotification"
# s.screenshots = "https://github.com/Yasashi/EBForeNotification/raw/master/screenshot/screenshot01.gif", "https://github.com/Yasashi/EBForeNotification/raw/master/screenshot/screenshot02.gif"


# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Licensing your code is important. See http://choosealicense.com for more info.
# CocoaPods will detect a license file if there is a named LICENSE*
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
#

#s.license = "MIT"
s.license = { :type => "MIT", :file => "LICENSE" }
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }


# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the authors of the library, with email addresses. Email addresses
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
# accepts just a name if you'd rather not provide an email address.
#
# Specify a social_media_url where others can refer to, for example a twitter
# profile URL.
#

s.author = { "E.B" => "[email protected]" }
# Or just: s.author = "E.B"
# s.authors = { "E.B" => "[email protected]" }
# s.social_media_url = "http://twitter.com/E.B"

# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If this Pod runs only on iOS or OS X, then specify the platform and
# the deployment target. You can optionally include the target after the platform.
#

# s.platform = :ios
s.platform = :ios, "7.0"

# When using multiple platforms
s.ios.deployment_target = "7.0"
# s.osx.deployment_target = "10.7"
# s.watchos.deployment_target = "2.0"
# s.tvos.deployment_target = "9.0"


# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#

s.source = { :git => "https://github.com/Yasashi/EBForeNotification.git", :tag => "#{s.version}" }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# CocoaPods is smart about how it includes source code. For source files
# giving a folder will include any swift, h, m, mm, c & cpp files.
# For header files it will include any header in the folder.
# Not including the public_header_files will make all headers public.
#

#s.source_files = "Classes", "Classes/**/*.{h,m}"
s.source_files = "EBForeNotification", "EBForeNotification/*.{h,m}"

#s.exclude_files = "Classes/Exclude"

s.public_header_files = "EBForeNotification/EBForeNotification.h"


# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# A list of resources included with the Pod. These are copied into the
# target bundle with a build phase script. Anything else will be cleaned.
# You can preserve files from being cleaned, please don't preserve
# non-essential files like tests, examples and documentation.
#

# s.resource = "icon.png"
s.resources = "EBForeNotification/*.xib"

# s.preserve_paths = "FilesToSave", "MoreFilesToSave"


# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Link your library with frameworks, or libraries. Libraries do not include
# the lib prefix of their name.
#

# s.framework = "SomeFramework"
s.frameworks = "UIKit", "Foundation", "AudioToolbox"

s.library = "objc"
# s.libraries = "iconv", "xml2"


# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If your library depends on compiler flags you can set them in the xcconfig hash
# where they will only apply to your library. If you depend on other Podspecs
# you can include multiple dependencies to ensure it works.

# s.requires_arc = true

# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
# s.dependency "JSONKit", "~> 1.4"

end
19 changes: 19 additions & 0 deletions EBForeNotification/EBBannerView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// EBBannerView.h
// iOS-Foreground-Push-Notification
//
// Created by wuxingchen on 16/7/21.
// Copyright © 2016年 [email protected]. All rights reserved.
//

#import <UIKit/UIKit.h>

#define BannerStayTime 4.7
#define BannerAnimationTime 0.3

@interface EBBannerView : UIView
@property (nonatomic, retain)NSDictionary *userInfo;
-(void)removeWithAnimation;
@end

static EBBannerView *SharedBannerView;
128 changes: 128 additions & 0 deletions EBForeNotification/EBBannerView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//
// EBBannerView.m
// iOS-Foreground-Push-Notification
//
// Created by wuxingchen on 16/7/21.
// Copyright © 2016年 [email protected]. All rights reserved.
//

#import "EBBannerView.h"
#import "EBForeNotification.h"
#import "UIViewController+EBForeNotification.h"
#import "UIImage+ColorAtPoint.h"

@interface EBBannerView()

@property (weak, nonatomic) IBOutlet UIImageView *icon_image;
@property (weak, nonatomic) IBOutlet UILabel *title_label;
@property (weak, nonatomic) IBOutlet UILabel *content_label;
@property (weak, nonatomic) IBOutlet UILabel *time_label;
@property (weak, nonatomic) IBOutlet UIView *line_view;
@end

@implementation EBBannerView

#define BannerHeight 70
#define BannerWidth [UIScreen mainScreen].bounds.size.width

-(void)awakeFromNib{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
self.userInfo = [NSDictionary dictionary];
[self apperWithAnimation];
[self addGestureRecognizer];
[super awakeFromNib];
}

-(void)setUserInfo:(NSDictionary *)userInfo{
_userInfo = userInfo;
UIImage *appIcon;
appIcon = [UIImage imageNamed:@"AppIcon60x60"];
if (!appIcon) {
appIcon = [UIImage imageNamed:@"AppIcon40x40"];
}
[self.icon_image setImage:appIcon];
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
// app名称
NSString *appName = [infoDictionary objectForKey:@"CFBundleName"];
if (!appName) {
appName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
}
//appName = @"input a app name here"; //if appName = nil, unsign this line and change it to you'r own app name.
if (!appName) {
assert(0);
}
self.title_label.text = appName;
self.content_label.text = self.userInfo[@"aps"][@"alert"];
self.time_label.text = EBBannerViewTimeText;
self.time_label.textColor = [UIImage colorAtPoint:self.time_label.center];
self.time_label.alpha = 0.7;
self.line_view.backgroundColor = [UIImage colorAtPoint:self.line_view.center];
self.line_view.alpha = 0.7;
}

-(void)statusBarOrientationChange:(NSNotification *)notification{
self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 77);
}

-(void)addGestureRecognizer{
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionUp;
[self addGestureRecognizer:swipeGesture];

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
[self addGestureRecognizer:tapGesture];
}

-(void)tapGesture:(UITapGestureRecognizer*)tapGesture{
[[NSNotificationCenter defaultCenter] postNotificationName:EBBannerViewDidClick object:self.userInfo];
[self removeWithAnimation];
}

-(void)swipeGesture:(UISwipeGestureRecognizer*)gesture{
[self removeWithAnimation];
}

-(void)apperWithAnimation{
if ([[EBBannerView appRootViewController] isKindOfClass:[UINavigationController class]]) {
UINavigationController *controller = (UINavigationController*)[EBBannerView appRootViewController];
controller.EBForegroundNotificationStatusBarHidden = YES;
controller.childViewControllerForStatusBarHidden.EBForegroundNotificationStatusBarHidden = YES;
}else{
[EBBannerView appRootViewController].EBForegroundNotificationStatusBarHidden = YES;
}
self.frame = CGRectMake(0, 0, BannerWidth, 0);
[UIView animateWithDuration:BannerAnimationTime animations:^{
self.frame = CGRectMake(0, 0, BannerWidth, BannerHeight);
} completion:^(BOOL finished) {
self.frame = CGRectMake(0, 0, BannerWidth, BannerHeight);
}];
}

-(void)removeWithAnimation{
//anitamtion
[UIView animateWithDuration:BannerAnimationTime animations:^{
self.frame = CGRectMake(0, 0, BannerWidth, 0);
} completion:^(BOOL finished) {
self.frame = CGRectMake(0, 0, BannerWidth, 0);
[self removeFromSuperview];
if ([[EBBannerView appRootViewController] isKindOfClass:[UINavigationController class]]) {
UINavigationController *controller = (UINavigationController*)[EBBannerView appRootViewController];
controller.childViewControllerForStatusBarHidden.EBForegroundNotificationStatusBarHidden = NO;
controller.EBForegroundNotificationStatusBarHidden = NO;
}else{
[EBBannerView appRootViewController].EBForegroundNotificationStatusBarHidden = YES;
}
SharedBannerView = nil;
}];
}

+(UIViewController *)appRootViewController{
UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *topVC = appRootVC;
while (topVC.presentedViewController) {
topVC = topVC.presentedViewController;
}
return topVC;
}

@end
Loading

0 comments on commit 871cfd0

Please sign in to comment.