Skip to content

Commit 871cfd0

Browse files
committed
Merge branch 'dev'
2 parents 590cc55 + eff13a0 commit 871cfd0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2825
-2
lines changed

EBForeNotification.podspec

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#
2+
# Be sure to run `pod spec lint EBForeNotification.podspec' to ensure this is a
3+
# valid spec and to remove all comments including this before submitting the spec.
4+
#
5+
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
6+
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
7+
#
8+
9+
Pod::Spec.new do |s|
10+
11+
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
12+
#
13+
# These will help people to find your library, and whilst it
14+
# can feel like a chore to fill in it's definitely to your advantage. The
15+
# summary should be tweet-length, and the description more in depth.
16+
#
17+
18+
s.name = "EBForeNotification"
19+
s.version = "1.1.0"
20+
s.summary = "iOS 前台推送及事件处理。iOS Foreground Push Notification and event-handle."
21+
22+
# This description is used to generate tags and improve search results.
23+
# * Think: What does it do? Why did you write it? What is the focus?
24+
# * Try to keep it short, snappy and to the point.
25+
# * Write the description between the DESC delimiters below.
26+
# * Finally, don't worry about the indent, CocoaPods strips it!
27+
s.description = <<-DESC
28+
在 App 处于前台时展示跟系统完全一样的推送弹窗和声音。获取推送内容,并处理点击事件。iOS Foreground Push Notification, the same as the system style, both Banner and Sound.
29+
DESC
30+
31+
s.homepage = "https://github.com/Yasashi/EBForeNotification"
32+
# s.screenshots = "https://github.com/Yasashi/EBForeNotification/raw/master/screenshot/screenshot01.gif", "https://github.com/Yasashi/EBForeNotification/raw/master/screenshot/screenshot02.gif"
33+
34+
35+
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
36+
#
37+
# Licensing your code is important. See http://choosealicense.com for more info.
38+
# CocoaPods will detect a license file if there is a named LICENSE*
39+
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
40+
#
41+
42+
#s.license = "MIT"
43+
s.license = { :type => "MIT", :file => "LICENSE" }
44+
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }
45+
46+
47+
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
48+
#
49+
# Specify the authors of the library, with email addresses. Email addresses
50+
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
51+
# accepts just a name if you'd rather not provide an email address.
52+
#
53+
# Specify a social_media_url where others can refer to, for example a twitter
54+
# profile URL.
55+
#
56+
57+
s.author = { "E.B" => "[email protected]" }
58+
# Or just: s.author = "E.B"
59+
# s.authors = { "E.B" => "[email protected]" }
60+
# s.social_media_url = "http://twitter.com/E.B"
61+
62+
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
63+
#
64+
# If this Pod runs only on iOS or OS X, then specify the platform and
65+
# the deployment target. You can optionally include the target after the platform.
66+
#
67+
68+
# s.platform = :ios
69+
s.platform = :ios, "7.0"
70+
71+
# When using multiple platforms
72+
s.ios.deployment_target = "7.0"
73+
# s.osx.deployment_target = "10.7"
74+
# s.watchos.deployment_target = "2.0"
75+
# s.tvos.deployment_target = "9.0"
76+
77+
78+
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
79+
#
80+
# Specify the location from where the source should be retrieved.
81+
# Supports git, hg, bzr, svn and HTTP.
82+
#
83+
84+
s.source = { :git => "https://github.com/Yasashi/EBForeNotification.git", :tag => "#{s.version}" }
85+
86+
87+
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
88+
#
89+
# CocoaPods is smart about how it includes source code. For source files
90+
# giving a folder will include any swift, h, m, mm, c & cpp files.
91+
# For header files it will include any header in the folder.
92+
# Not including the public_header_files will make all headers public.
93+
#
94+
95+
#s.source_files = "Classes", "Classes/**/*.{h,m}"
96+
s.source_files = "EBForeNotification", "EBForeNotification/*.{h,m}"
97+
98+
#s.exclude_files = "Classes/Exclude"
99+
100+
s.public_header_files = "EBForeNotification/EBForeNotification.h"
101+
102+
103+
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
104+
#
105+
# A list of resources included with the Pod. These are copied into the
106+
# target bundle with a build phase script. Anything else will be cleaned.
107+
# You can preserve files from being cleaned, please don't preserve
108+
# non-essential files like tests, examples and documentation.
109+
#
110+
111+
# s.resource = "icon.png"
112+
s.resources = "EBForeNotification/*.xib"
113+
114+
# s.preserve_paths = "FilesToSave", "MoreFilesToSave"
115+
116+
117+
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
118+
#
119+
# Link your library with frameworks, or libraries. Libraries do not include
120+
# the lib prefix of their name.
121+
#
122+
123+
# s.framework = "SomeFramework"
124+
s.frameworks = "UIKit", "Foundation", "AudioToolbox"
125+
126+
s.library = "objc"
127+
# s.libraries = "iconv", "xml2"
128+
129+
130+
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
131+
#
132+
# If your library depends on compiler flags you can set them in the xcconfig hash
133+
# where they will only apply to your library. If you depend on other Podspecs
134+
# you can include multiple dependencies to ensure it works.
135+
136+
# s.requires_arc = true
137+
138+
# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
139+
# s.dependency "JSONKit", "~> 1.4"
140+
141+
end

EBForeNotification/EBBannerView.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// EBBannerView.h
3+
// iOS-Foreground-Push-Notification
4+
//
5+
// Created by wuxingchen on 16/7/21.
6+
// Copyright © 2016年 [email protected]. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
#define BannerStayTime 4.7
12+
#define BannerAnimationTime 0.3
13+
14+
@interface EBBannerView : UIView
15+
@property (nonatomic, retain)NSDictionary *userInfo;
16+
-(void)removeWithAnimation;
17+
@end
18+
19+
static EBBannerView *SharedBannerView;

EBForeNotification/EBBannerView.m

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
//
2+
// EBBannerView.m
3+
// iOS-Foreground-Push-Notification
4+
//
5+
// Created by wuxingchen on 16/7/21.
6+
// Copyright © 2016年 [email protected]. All rights reserved.
7+
//
8+
9+
#import "EBBannerView.h"
10+
#import "EBForeNotification.h"
11+
#import "UIViewController+EBForeNotification.h"
12+
#import "UIImage+ColorAtPoint.h"
13+
14+
@interface EBBannerView()
15+
16+
@property (weak, nonatomic) IBOutlet UIImageView *icon_image;
17+
@property (weak, nonatomic) IBOutlet UILabel *title_label;
18+
@property (weak, nonatomic) IBOutlet UILabel *content_label;
19+
@property (weak, nonatomic) IBOutlet UILabel *time_label;
20+
@property (weak, nonatomic) IBOutlet UIView *line_view;
21+
@end
22+
23+
@implementation EBBannerView
24+
25+
#define BannerHeight 70
26+
#define BannerWidth [UIScreen mainScreen].bounds.size.width
27+
28+
-(void)awakeFromNib{
29+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
30+
self.userInfo = [NSDictionary dictionary];
31+
[self apperWithAnimation];
32+
[self addGestureRecognizer];
33+
[super awakeFromNib];
34+
}
35+
36+
-(void)setUserInfo:(NSDictionary *)userInfo{
37+
_userInfo = userInfo;
38+
UIImage *appIcon;
39+
appIcon = [UIImage imageNamed:@"AppIcon60x60"];
40+
if (!appIcon) {
41+
appIcon = [UIImage imageNamed:@"AppIcon40x40"];
42+
}
43+
[self.icon_image setImage:appIcon];
44+
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
45+
// app名称
46+
NSString *appName = [infoDictionary objectForKey:@"CFBundleName"];
47+
if (!appName) {
48+
appName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
49+
}
50+
//appName = @"input a app name here"; //if appName = nil, unsign this line and change it to you'r own app name.
51+
if (!appName) {
52+
assert(0);
53+
}
54+
self.title_label.text = appName;
55+
self.content_label.text = self.userInfo[@"aps"][@"alert"];
56+
self.time_label.text = EBBannerViewTimeText;
57+
self.time_label.textColor = [UIImage colorAtPoint:self.time_label.center];
58+
self.time_label.alpha = 0.7;
59+
self.line_view.backgroundColor = [UIImage colorAtPoint:self.line_view.center];
60+
self.line_view.alpha = 0.7;
61+
}
62+
63+
-(void)statusBarOrientationChange:(NSNotification *)notification{
64+
self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 77);
65+
}
66+
67+
-(void)addGestureRecognizer{
68+
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
69+
swipeGesture.direction = UISwipeGestureRecognizerDirectionUp;
70+
[self addGestureRecognizer:swipeGesture];
71+
72+
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
73+
[self addGestureRecognizer:tapGesture];
74+
}
75+
76+
-(void)tapGesture:(UITapGestureRecognizer*)tapGesture{
77+
[[NSNotificationCenter defaultCenter] postNotificationName:EBBannerViewDidClick object:self.userInfo];
78+
[self removeWithAnimation];
79+
}
80+
81+
-(void)swipeGesture:(UISwipeGestureRecognizer*)gesture{
82+
[self removeWithAnimation];
83+
}
84+
85+
-(void)apperWithAnimation{
86+
if ([[EBBannerView appRootViewController] isKindOfClass:[UINavigationController class]]) {
87+
UINavigationController *controller = (UINavigationController*)[EBBannerView appRootViewController];
88+
controller.EBForegroundNotificationStatusBarHidden = YES;
89+
controller.childViewControllerForStatusBarHidden.EBForegroundNotificationStatusBarHidden = YES;
90+
}else{
91+
[EBBannerView appRootViewController].EBForegroundNotificationStatusBarHidden = YES;
92+
}
93+
self.frame = CGRectMake(0, 0, BannerWidth, 0);
94+
[UIView animateWithDuration:BannerAnimationTime animations:^{
95+
self.frame = CGRectMake(0, 0, BannerWidth, BannerHeight);
96+
} completion:^(BOOL finished) {
97+
self.frame = CGRectMake(0, 0, BannerWidth, BannerHeight);
98+
}];
99+
}
100+
101+
-(void)removeWithAnimation{
102+
//anitamtion
103+
[UIView animateWithDuration:BannerAnimationTime animations:^{
104+
self.frame = CGRectMake(0, 0, BannerWidth, 0);
105+
} completion:^(BOOL finished) {
106+
self.frame = CGRectMake(0, 0, BannerWidth, 0);
107+
[self removeFromSuperview];
108+
if ([[EBBannerView appRootViewController] isKindOfClass:[UINavigationController class]]) {
109+
UINavigationController *controller = (UINavigationController*)[EBBannerView appRootViewController];
110+
controller.childViewControllerForStatusBarHidden.EBForegroundNotificationStatusBarHidden = NO;
111+
controller.EBForegroundNotificationStatusBarHidden = NO;
112+
}else{
113+
[EBBannerView appRootViewController].EBForegroundNotificationStatusBarHidden = YES;
114+
}
115+
SharedBannerView = nil;
116+
}];
117+
}
118+
119+
+(UIViewController *)appRootViewController{
120+
UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
121+
UIViewController *topVC = appRootVC;
122+
while (topVC.presentedViewController) {
123+
topVC = topVC.presentedViewController;
124+
}
125+
return topVC;
126+
}
127+
128+
@end

0 commit comments

Comments
 (0)