diff --git a/EBForeNotification.podspec b/EBForeNotification.podspec new file mode 100644 index 0000000..2ced614 --- /dev/null +++ b/EBForeNotification.podspec @@ -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" => "57380422@qq.com" } + # Or just: s.author = "E.B" + # s.authors = { "E.B" => "57380422@qq.com" } + # 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 diff --git a/EBForeNotification/EBBannerView.h b/EBForeNotification/EBBannerView.h new file mode 100644 index 0000000..eb11c16 --- /dev/null +++ b/EBForeNotification/EBBannerView.h @@ -0,0 +1,19 @@ +// +// EBBannerView.h +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import + +#define BannerStayTime 4.7 +#define BannerAnimationTime 0.3 + +@interface EBBannerView : UIView +@property (nonatomic, retain)NSDictionary *userInfo; +-(void)removeWithAnimation; +@end + +static EBBannerView *SharedBannerView; diff --git a/EBForeNotification/EBBannerView.m b/EBForeNotification/EBBannerView.m new file mode 100644 index 0000000..cd46fec --- /dev/null +++ b/EBForeNotification/EBBannerView.m @@ -0,0 +1,128 @@ +// +// EBBannerView.m +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. 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 diff --git a/EBForeNotification/EBBannerView.xib b/EBForeNotification/EBBannerView.xib new file mode 100644 index 0000000..654cd95 --- /dev/null +++ b/EBForeNotification/EBBannerView.xib @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/EBForeNotification/EBForeNotification.m b/EBForeNotification/EBForeNotification.m new file mode 100644 index 0000000..ec01d4a --- /dev/null +++ b/EBForeNotification/EBForeNotification.m @@ -0,0 +1,71 @@ +// +// EBForeNotification.m +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import "EBForeNotification.h" +#import +#import +#import "EBBannerView.h" +#import "UIViewController+EBForeNotification.h" + +NSString *const EBBannerViewDidClick = @"EBBannerViewDidClick"; + +@implementation EBForeNotification + +#pragma mark - public + ++(void)handleRemoteNotification:(NSDictionary*)userInfo soundID:(int)soundID{ + if (userInfo) { + [EBBannerView class]; + id aps = [userInfo valueForKey:@"aps"]; + if (aps && [aps isKindOfClass:[NSDictionary class]] && [aps valueForKey:@"alert"] && ![[aps valueForKey:@"alert"] isEqual: @""]) { + [EBForeNotification showBannerWithUserInfo:userInfo soundID:soundID]; + } + } +} + ++(void)handleRemoteNotification:(NSDictionary*)userInfo customSound:(NSString*)soundName{ + if (soundName) { + NSURL *url = [[NSBundle mainBundle] URLForResource:soundName withExtension:nil]; + SystemSoundID soundID = 0; + AudioServicesCreateSystemSoundID((__bridge CFURLRef)(url), &soundID); + [EBForeNotification handleRemoteNotification:userInfo soundID:soundID]; + } +} + +#pragma mark - private + ++(void)showBannerWithUserInfo:(NSDictionary*)userInfo soundID:(int)soundID{ + if (soundID) { + AudioServicesPlaySystemSound(soundID); + } + if (SharedBannerView) { + SharedBannerView = nil; + } + SharedBannerView = [[NSBundle mainBundle] loadNibNamed:@"EBBannerView" owner:nil options:nil].lastObject; + UIViewController *controller = [EBForeNotification appRootViewController]; + SharedBannerView.userInfo = userInfo; + [controller.view addSubview:SharedBannerView]; + [NSTimer scheduledTimerWithTimeInterval:BannerStayTime target:self selector:@selector(deleteBanner) userInfo:nil repeats:NO]; +} + ++(UIViewController *)appRootViewController{ + UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController; + UIViewController *topVC = appRootVC; + while (topVC.presentedViewController) { + topVC = topVC.presentedViewController; + } + return topVC; +} + ++(void)deleteBanner{ + if (SharedBannerView) { + [SharedBannerView removeWithAnimation]; + } +} + +@end diff --git a/EBForeNotification/EBForeNotificationBundle.bundle/EBBannerView~iphone.nib/objects-8.0+.nib b/EBForeNotification/EBForeNotificationBundle.bundle/EBBannerView~iphone.nib/objects-8.0+.nib deleted file mode 100644 index 32aa16e..0000000 Binary files a/EBForeNotification/EBForeNotificationBundle.bundle/EBBannerView~iphone.nib/objects-8.0+.nib and /dev/null differ diff --git a/EBForeNotification/EBForeNotificationBundle.bundle/EBBannerView~iphone.nib/runtime.nib b/EBForeNotification/EBForeNotificationBundle.bundle/EBBannerView~iphone.nib/runtime.nib deleted file mode 100644 index 78124ac..0000000 Binary files a/EBForeNotification/EBForeNotificationBundle.bundle/EBBannerView~iphone.nib/runtime.nib and /dev/null differ diff --git a/EBForeNotification/EBForeNotificationBundle.bundle/Info.plist b/EBForeNotification/EBForeNotificationBundle.bundle/Info.plist deleted file mode 100644 index d4084a1..0000000 Binary files a/EBForeNotification/EBForeNotificationBundle.bundle/Info.plist and /dev/null differ diff --git a/EBForeNotification/UIImage+ColorAtPoint.h b/EBForeNotification/UIImage+ColorAtPoint.h new file mode 100644 index 0000000..00c84bd --- /dev/null +++ b/EBForeNotification/UIImage+ColorAtPoint.h @@ -0,0 +1,13 @@ +// +// UIImage+ColorAtPoint.h +// EBForeNotification +// +// Created by wuxingchen on 16/7/22. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import + +@interface UIImage (ColorAtPoint) ++(UIColor *)colorAtPoint:(CGPoint)point; +@end diff --git a/EBForeNotification/UIImage+ColorAtPoint.m b/EBForeNotification/UIImage+ColorAtPoint.m new file mode 100644 index 0000000..96e091e --- /dev/null +++ b/EBForeNotification/UIImage+ColorAtPoint.m @@ -0,0 +1,90 @@ +// +// UIImage+ColorAtPoint.m +// EBForeNotification +// +// Created by wuxingchen on 16/7/22. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import "UIImage+ColorAtPoint.h" + +@implementation UIImage (ColorAtPoint) + ++(UIColor *)colorAtPoint:(CGPoint)point{ + UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow]; + UIGraphicsBeginImageContext(screenWindow.frame.size);//全屏截图,包括window + + [screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()]; + + UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); + + + if (!CGRectContainsPoint(CGRectMake(0.0f, 0.0f, viewImage.size.width, viewImage.size.height), point)) { + + return nil; + + } + + + NSInteger pointX = trunc(point.x); + + NSInteger pointY = trunc(point.y); + + CGImageRef cgImage = viewImage.CGImage; + + NSUInteger width = viewImage.size.width; + + NSUInteger height = viewImage.size.height; + + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + int bytesPerPixel = 4; + + int bytesPerRow = bytesPerPixel * 1; + + NSUInteger bitsPerComponent = 8; + + unsigned char pixelData[4] = { 0, 0, 0, 0 }; + + CGContextRef context = CGBitmapContextCreate(pixelData, + + 1, + + 1, + + bitsPerComponent, + + bytesPerRow, + + colorSpace, + + kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); + + CGColorSpaceRelease(colorSpace); + + CGContextSetBlendMode(context, kCGBlendModeCopy); + + + // Draw the pixel we are interested in onto the bitmap context + + CGContextTranslateCTM(context, -pointX, pointY-(CGFloat)height); + + CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, (CGFloat)width, (CGFloat)height), cgImage); + + CGContextRelease(context); + + // Convert color values [0..255] to floats [0.0..1.0] + + CGFloat red = (CGFloat)pixelData[0] / 255.0f; + + CGFloat green = (CGFloat)pixelData[1] / 255.0f; + + CGFloat blue = (CGFloat)pixelData[2] / 255.0f; + + CGFloat alpha = (CGFloat)pixelData[3] / 255.0f; + + return [UIColor colorWithRed:red green:green blue:blue alpha:alpha]; +} + + +@end diff --git a/EBForeNotification/UIViewController+EBForeNotification.h b/EBForeNotification/UIViewController+EBForeNotification.h new file mode 100644 index 0000000..f5c2df2 --- /dev/null +++ b/EBForeNotification/UIViewController+EBForeNotification.h @@ -0,0 +1,14 @@ +// +// UIViewController+EBForeNotification.h +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import + +@interface UIViewController (EBForeNotification) +@property(nonatomic, assign)BOOL EBForegroundNotificationStatusBarHidden; + +@end diff --git a/EBForeNotification/UIViewController+EBForeNotification.m b/EBForeNotification/UIViewController+EBForeNotification.m new file mode 100644 index 0000000..aa9cfa5 --- /dev/null +++ b/EBForeNotification/UIViewController+EBForeNotification.m @@ -0,0 +1,33 @@ +// +// UIViewController+EBForeNotification.m +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import "UIViewController+EBForeNotification.h" +#import + +@implementation UIViewController (EBForeNotification) + +static BOOL _EBForegroundNotificationStatusBarHidden; + +- (void)setEBForegroundNotificationStatusBarHidden:(BOOL)EBForegroundNotificationStatusBarHidden{ + NSNumber *t = @(EBForegroundNotificationStatusBarHidden); + objc_setAssociatedObject(self, &_EBForegroundNotificationStatusBarHidden, t, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + [self setNeedsStatusBarAppearanceUpdate]; +} + +- (BOOL)EBForegroundNotificationStatusBarHidden{ + NSNumber *t = objc_getAssociatedObject(self, &_EBForegroundNotificationStatusBarHidden); + return [t boolValue]; +} + +#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation" +-(BOOL)prefersStatusBarHidden{ + return self.EBForegroundNotificationStatusBarHidden; +} + +@end + diff --git a/EBForeNotification/libEBForeNotification.a b/EBForeNotification/libEBForeNotification.a deleted file mode 100644 index e15522f..0000000 Binary files a/EBForeNotification/libEBForeNotification.a and /dev/null differ diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..2a9984a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Pikachu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index c187c28..c0faa31 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,11 @@ QQ: 57380422 ## 安装 -1. 下载并`在 Xcode 中` `拖拽拷贝` `EBForeNotification` 文件夹至 Xcode 工程。 +### pod 安装 + pod "EBForeNotification" + +### 手动 安装 +1. 下载并`在 Xcode 中` `拖拽拷贝` 根目录中的 `EBForeNotification` 文件夹至 Xcode 工程。 2. `targets` --> `Build Settings` --> 搜 `other link` --> 添加 `-ObjC`。 ![](https://github.com/Yasashi/EBForeNotification/raw/master/screenshot/install.png) @@ -119,3 +123,5 @@ iOS 系统自带的声音 id,系统级的推送服务默认使用的是`三全 } ``` +## Demo +下载运行 [EBForeNotification demo](/demo) \ No newline at end of file diff --git a/README_ENGLISH.md b/README_ENGLISH.md index b857727..4035c27 100644 --- a/README_ENGLISH.md +++ b/README_ENGLISH.md @@ -19,6 +19,10 @@ Actual effect: ![](https://github.com/Yasashi/EBForeNotification/raw/master/screenshot/screenshot02.gif) ## Install +### pod + pod "EBForeNotification" + +### manual 1. Download and Drag `EBForeNotification` file folder into you Xcode project. 2. `targets` --> `Build Settings` --> search `other link` --> add `-ObjC` ![](https://github.com/Yasashi/EBForeNotification/raw/master/screenshot/install.png) @@ -110,4 +114,5 @@ Add observer: } ``` - +## Demo +Download and run [EBForeNotification demo](/demo) diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/project.pbxproj b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/project.pbxproj new file mode 100644 index 0000000..11b699c --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/project.pbxproj @@ -0,0 +1,444 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 0901F52012465E429D4C4EF8 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3F65F450C6E72513995C5B87 /* CoreGraphics.framework */; }; + 0D8698411D40989000AEE574 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D8698401D40989000AEE574 /* main.m */; }; + 0D8698441D40989000AEE574 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D8698431D40989000AEE574 /* AppDelegate.m */; }; + 0D8698471D40989000AEE574 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D8698461D40989000AEE574 /* ViewController.m */; }; + 0D86984A1D40989000AEE574 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0D8698481D40989000AEE574 /* Main.storyboard */; }; + 0D86984C1D40989000AEE574 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0D86984B1D40989000AEE574 /* Assets.xcassets */; }; + 0D86984F1D40989000AEE574 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0D86984D1D40989000AEE574 /* LaunchScreen.storyboard */; }; + 0DA209081D488C2B00199C53 /* EBBannerView.h in Headers */ = {isa = PBXBuildFile; fileRef = 0DA208FF1D488C2A00199C53 /* EBBannerView.h */; }; + 0DA209091D488C2B00199C53 /* EBBannerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DA209001D488C2A00199C53 /* EBBannerView.m */; }; + 0DA2090A1D488C2B00199C53 /* EBBannerView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0DA209011D488C2A00199C53 /* EBBannerView.xib */; }; + 0DA2090B1D488C2B00199C53 /* EBForeNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = 0DA209021D488C2B00199C53 /* EBForeNotification.h */; }; + 0DA2090C1D488C2B00199C53 /* EBForeNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DA209031D488C2B00199C53 /* EBForeNotification.m */; }; + 0DA2090D1D488C2B00199C53 /* UIImage+ColorAtPoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 0DA209041D488C2B00199C53 /* UIImage+ColorAtPoint.h */; }; + 0DA2090E1D488C2B00199C53 /* UIImage+ColorAtPoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DA209051D488C2B00199C53 /* UIImage+ColorAtPoint.m */; }; + 0DA2090F1D488C2B00199C53 /* UIViewController+EBForeNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = 0DA209061D488C2B00199C53 /* UIViewController+EBForeNotification.h */; }; + 0DA209101D488C2B00199C53 /* UIViewController+EBForeNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DA209071D488C2B00199C53 /* UIViewController+EBForeNotification.m */; }; + 171B5D9A0575676017E8EE61 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A0FFDCE723D5845050270ABC /* CFNetwork.framework */; }; + 17C43ECA53E22D1ADD65C11F /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DCF6E72182B28B48D76FA8BD /* CoreFoundation.framework */; }; + 3B3C7C166BA15C1F3089197D /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 217CFE021A532761C428C35E /* libz.tbd */; }; + 3B5F1FE1D93CC2C06E5E9A96 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FB0CEE0D100522FD6E9B3F9F /* UIKit.framework */; }; + 3E36C94BB5B0D4F1F0CC0087 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F51F042396A63AE56240E1B4 /* CoreTelephony.framework */; }; + 752540B28C213F3CCDC963D4 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 734A3EE24F4A7DAD5AE342D2 /* Foundation.framework */; }; + 90525CA8CEE3768B9EAB9806 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A030C75952DAF217EBAD9317 /* AdSupport.framework */; }; + 97CCA0B1CC5027E8F97C7F9D /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 732D4F38B010C4E409D8957F /* Security.framework */; }; + B57B83AC59AF44FECE87330D /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963D478130C6B1393C87E088 /* SystemConfiguration.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 0D86983C1D40989000AEE574 /* iOS-Foreground-Push-Notification.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "iOS-Foreground-Push-Notification.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 0D8698401D40989000AEE574 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 0D8698421D40989000AEE574 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 0D8698431D40989000AEE574 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 0D8698451D40989000AEE574 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 0D8698461D40989000AEE574 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 0D8698491D40989000AEE574 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 0D86984B1D40989000AEE574 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 0D86984E1D40989000AEE574 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 0D8698501D40989000AEE574 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 0DA208FF1D488C2A00199C53 /* EBBannerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EBBannerView.h; sourceTree = ""; }; + 0DA209001D488C2A00199C53 /* EBBannerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EBBannerView.m; sourceTree = ""; }; + 0DA209011D488C2A00199C53 /* EBBannerView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EBBannerView.xib; sourceTree = ""; }; + 0DA209021D488C2B00199C53 /* EBForeNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EBForeNotification.h; sourceTree = ""; }; + 0DA209031D488C2B00199C53 /* EBForeNotification.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EBForeNotification.m; sourceTree = ""; }; + 0DA209041D488C2B00199C53 /* UIImage+ColorAtPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+ColorAtPoint.h"; sourceTree = ""; }; + 0DA209051D488C2B00199C53 /* UIImage+ColorAtPoint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+ColorAtPoint.m"; sourceTree = ""; }; + 0DA209061D488C2B00199C53 /* UIViewController+EBForeNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+EBForeNotification.h"; sourceTree = ""; }; + 0DA209071D488C2B00199C53 /* UIViewController+EBForeNotification.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+EBForeNotification.m"; sourceTree = ""; }; + 217CFE021A532761C428C35E /* libz.tbd */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; + 3F65F450C6E72513995C5B87 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/CoreGraphics.framework; sourceTree = DEVELOPER_DIR; }; + 732D4F38B010C4E409D8957F /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/Security.framework; sourceTree = DEVELOPER_DIR; }; + 734A3EE24F4A7DAD5AE342D2 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; + 963D478130C6B1393C87E088 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/SystemConfiguration.framework; sourceTree = DEVELOPER_DIR; }; + A030C75952DAF217EBAD9317 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/AdSupport.framework; sourceTree = DEVELOPER_DIR; }; + A0FFDCE723D5845050270ABC /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/CFNetwork.framework; sourceTree = DEVELOPER_DIR; }; + DCF6E72182B28B48D76FA8BD /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/CoreFoundation.framework; sourceTree = DEVELOPER_DIR; }; + F51F042396A63AE56240E1B4 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/CoreTelephony.framework; sourceTree = DEVELOPER_DIR; }; + FB0CEE0D100522FD6E9B3F9F /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 0D8698391D40989000AEE574 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 171B5D9A0575676017E8EE61 /* CFNetwork.framework in Frameworks */, + 17C43ECA53E22D1ADD65C11F /* CoreFoundation.framework in Frameworks */, + 3E36C94BB5B0D4F1F0CC0087 /* CoreTelephony.framework in Frameworks */, + 0901F52012465E429D4C4EF8 /* CoreGraphics.framework in Frameworks */, + 752540B28C213F3CCDC963D4 /* Foundation.framework in Frameworks */, + 3B5F1FE1D93CC2C06E5E9A96 /* UIKit.framework in Frameworks */, + 97CCA0B1CC5027E8F97C7F9D /* Security.framework in Frameworks */, + B57B83AC59AF44FECE87330D /* SystemConfiguration.framework in Frameworks */, + 3B3C7C166BA15C1F3089197D /* libz.tbd in Frameworks */, + 90525CA8CEE3768B9EAB9806 /* AdSupport.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 0D469EEF1D4139B600086741 /* EBFN */ = { + isa = PBXGroup; + children = ( + 0DA208FF1D488C2A00199C53 /* EBBannerView.h */, + 0DA209001D488C2A00199C53 /* EBBannerView.m */, + 0DA209011D488C2A00199C53 /* EBBannerView.xib */, + 0DA209021D488C2B00199C53 /* EBForeNotification.h */, + 0DA209031D488C2B00199C53 /* EBForeNotification.m */, + 0DA209041D488C2B00199C53 /* UIImage+ColorAtPoint.h */, + 0DA209051D488C2B00199C53 /* UIImage+ColorAtPoint.m */, + 0DA209061D488C2B00199C53 /* UIViewController+EBForeNotification.h */, + 0DA209071D488C2B00199C53 /* UIViewController+EBForeNotification.m */, + ); + name = EBFN; + sourceTree = ""; + }; + 0D8698331D40989000AEE574 = { + isa = PBXGroup; + children = ( + 0D86983E1D40989000AEE574 /* iOS-Foreground-Push-Notification */, + 0D86983D1D40989000AEE574 /* Products */, + 5B083F6F790A62254983A11D /* Frameworks */, + ); + sourceTree = ""; + }; + 0D86983D1D40989000AEE574 /* Products */ = { + isa = PBXGroup; + children = ( + 0D86983C1D40989000AEE574 /* iOS-Foreground-Push-Notification.app */, + ); + name = Products; + sourceTree = ""; + }; + 0D86983E1D40989000AEE574 /* iOS-Foreground-Push-Notification */ = { + isa = PBXGroup; + children = ( + 0D469EEF1D4139B600086741 /* EBFN */, + 0D8698421D40989000AEE574 /* AppDelegate.h */, + 0D8698431D40989000AEE574 /* AppDelegate.m */, + 0D8698451D40989000AEE574 /* ViewController.h */, + 0D8698461D40989000AEE574 /* ViewController.m */, + 0D8698481D40989000AEE574 /* Main.storyboard */, + 0D86984B1D40989000AEE574 /* Assets.xcassets */, + 0D86984D1D40989000AEE574 /* LaunchScreen.storyboard */, + 0D8698501D40989000AEE574 /* Info.plist */, + 0D86983F1D40989000AEE574 /* Supporting Files */, + ); + path = "iOS-Foreground-Push-Notification"; + sourceTree = ""; + }; + 0D86983F1D40989000AEE574 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 0D8698401D40989000AEE574 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 512EB115CFDADBCC944459B6 /* iOS */ = { + isa = PBXGroup; + children = ( + A0FFDCE723D5845050270ABC /* CFNetwork.framework */, + DCF6E72182B28B48D76FA8BD /* CoreFoundation.framework */, + F51F042396A63AE56240E1B4 /* CoreTelephony.framework */, + 3F65F450C6E72513995C5B87 /* CoreGraphics.framework */, + 734A3EE24F4A7DAD5AE342D2 /* Foundation.framework */, + FB0CEE0D100522FD6E9B3F9F /* UIKit.framework */, + 732D4F38B010C4E409D8957F /* Security.framework */, + 963D478130C6B1393C87E088 /* SystemConfiguration.framework */, + A030C75952DAF217EBAD9317 /* AdSupport.framework */, + ); + name = iOS; + sourceTree = ""; + }; + 5B083F6F790A62254983A11D /* Frameworks */ = { + isa = PBXGroup; + children = ( + 512EB115CFDADBCC944459B6 /* iOS */, + 217CFE021A532761C428C35E /* libz.tbd */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + D5CB10CF793C85711DFACD55 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 0DA2090F1D488C2B00199C53 /* UIViewController+EBForeNotification.h in Headers */, + 0DA209081D488C2B00199C53 /* EBBannerView.h in Headers */, + 0DA2090B1D488C2B00199C53 /* EBForeNotification.h in Headers */, + 0DA2090D1D488C2B00199C53 /* UIImage+ColorAtPoint.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 0D86983B1D40989000AEE574 /* iOS-Foreground-Push-Notification */ = { + isa = PBXNativeTarget; + buildConfigurationList = 0D8698531D40989000AEE574 /* Build configuration list for PBXNativeTarget "iOS-Foreground-Push-Notification" */; + buildPhases = ( + 0D8698381D40989000AEE574 /* Sources */, + 0D8698391D40989000AEE574 /* Frameworks */, + 0D86983A1D40989000AEE574 /* Resources */, + D5CB10CF793C85711DFACD55 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "iOS-Foreground-Push-Notification"; + productName = "iOS-Foreground-Push-Notification"; + productReference = 0D86983C1D40989000AEE574 /* iOS-Foreground-Push-Notification.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 0D8698341D40989000AEE574 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0730; + ORGANIZATIONNAME = "57380422@qq.com"; + TargetAttributes = { + 0D86983B1D40989000AEE574 = { + CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = KE965R2D4S; + DevelopmentTeamName = "星辰 吴 (Personal Team)"; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 0D8698371D40989000AEE574 /* Build configuration list for PBXProject "iOS-Foreground-Push-Notification" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 0D8698331D40989000AEE574; + productRefGroup = 0D86983D1D40989000AEE574 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 0D86983B1D40989000AEE574 /* iOS-Foreground-Push-Notification */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 0D86983A1D40989000AEE574 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 0D86984F1D40989000AEE574 /* LaunchScreen.storyboard in Resources */, + 0DA2090A1D488C2B00199C53 /* EBBannerView.xib in Resources */, + 0D86984C1D40989000AEE574 /* Assets.xcassets in Resources */, + 0D86984A1D40989000AEE574 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 0D8698381D40989000AEE574 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 0D8698471D40989000AEE574 /* ViewController.m in Sources */, + 0DA2090C1D488C2B00199C53 /* EBForeNotification.m in Sources */, + 0DA209091D488C2B00199C53 /* EBBannerView.m in Sources */, + 0D8698441D40989000AEE574 /* AppDelegate.m in Sources */, + 0DA209101D488C2B00199C53 /* UIViewController+EBForeNotification.m in Sources */, + 0D8698411D40989000AEE574 /* main.m in Sources */, + 0DA2090E1D488C2B00199C53 /* UIImage+ColorAtPoint.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 0D8698481D40989000AEE574 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 0D8698491D40989000AEE574 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 0D86984D1D40989000AEE574 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 0D86984E1D40989000AEE574 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 0D8698511D40989000AEE574 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = "$(OTHER_LDFLAGS)"; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 0D8698521D40989000AEE574 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = NO; + OTHER_LDFLAGS = "$(OTHER_LDFLAGS)"; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 0D8698541D40989000AEE574 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_OBJC_ARC = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + INFOPLIST_FILE = "iOS-Foreground-Push-Notification/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/iOS-Foreground-Push-Notification", + ); + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_BUNDLE_IDENTIFIER = eb.jpush.demodd; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; + }; + name = Debug; + }; + 0D8698551D40989000AEE574 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_OBJC_ARC = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + INFOPLIST_FILE = "iOS-Foreground-Push-Notification/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/iOS-Foreground-Push-Notification", + ); + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_BUNDLE_IDENTIFIER = eb.jpush.demodd; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 0D8698371D40989000AEE574 /* Build configuration list for PBXProject "iOS-Foreground-Push-Notification" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 0D8698511D40989000AEE574 /* Debug */, + 0D8698521D40989000AEE574 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 0D8698531D40989000AEE574 /* Build configuration list for PBXNativeTarget "iOS-Foreground-Push-Notification" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 0D8698541D40989000AEE574 /* Debug */, + 0D8698551D40989000AEE574 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 0D8698341D40989000AEE574 /* Project object */; +} diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..afa4940 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/project.xcworkspace/xcuserdata/wuxingchen.xcuserdatad/UserInterfaceState.xcuserstate b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/project.xcworkspace/xcuserdata/wuxingchen.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..9849ef9 Binary files /dev/null and b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/project.xcworkspace/xcuserdata/wuxingchen.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/xcuserdata/wuxingchen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/xcuserdata/wuxingchen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..bd6bb1d --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/xcuserdata/wuxingchen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,23 @@ + + + + + + + + + diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/xcuserdata/wuxingchen.xcuserdatad/xcschemes/iOS-Foreground-Push-Notification.xcscheme b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/xcuserdata/wuxingchen.xcuserdatad/xcschemes/iOS-Foreground-Push-Notification.xcscheme new file mode 100644 index 0000000..86deb17 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/xcuserdata/wuxingchen.xcuserdatad/xcschemes/iOS-Foreground-Push-Notification.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/xcuserdata/wuxingchen.xcuserdatad/xcschemes/xcschememanagement.plist b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/xcuserdata/wuxingchen.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..63558b5 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/xcuserdata/wuxingchen.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + iOS-Foreground-Push-Notification.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 0D86983B1D40989000AEE574 + + primary + + + + + diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/AppDelegate.h b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/AppDelegate.h new file mode 100644 index 0000000..e28d44e --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/AppDelegate.h @@ -0,0 +1,17 @@ +// +// AppDelegate.h +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/AppDelegate.m b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/AppDelegate.m new file mode 100644 index 0000000..987c7f6 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/AppDelegate.m @@ -0,0 +1,65 @@ +// +// AppDelegate.m +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import "AppDelegate.h" +#import "EBForeNotification.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + + +-(void)dddd:(NSNotification*)noti{ + NSLog(@"ddd,%@",noti); +} + +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { + // JPush sdk + [EBForeNotification handleRemoteNotification:userInfo customSound:@"my_Sound.wav"]; + [EBForeNotification handleRemoteNotification:userInfo soundID:1312]; +} + +//IOS7 only +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { + [EBForeNotification handleRemoteNotification:userInfo soundID:1312]; + completionHandler(UIBackgroundFetchResultNewData); +} + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dddd:) name:EBBannerViewDidClick object:nil]; + + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. +} + +- (void)applicationDidEnterBackground:(UIApplication *)application { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + +- (void)applicationWillEnterForeground:(UIApplication *)application { + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. +} + +- (void)applicationDidBecomeActive:(UIApplication *)application { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + +- (void)applicationWillTerminate:(UIApplication *)application { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + +@end diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Assets.xcassets/AppIcon.appiconset/Contents.json b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..6f41b1d --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,40 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "qq_icon.png", + "scale" : "2x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "qq_icon-1.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Assets.xcassets/AppIcon.appiconset/qq_icon-1.png b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Assets.xcassets/AppIcon.appiconset/qq_icon-1.png new file mode 100644 index 0000000..292a383 Binary files /dev/null and b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Assets.xcassets/AppIcon.appiconset/qq_icon-1.png differ diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Assets.xcassets/AppIcon.appiconset/qq_icon.png b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Assets.xcassets/AppIcon.appiconset/qq_icon.png new file mode 100644 index 0000000..292a383 Binary files /dev/null and b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Assets.xcassets/AppIcon.appiconset/qq_icon.png differ diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Base.lproj/LaunchScreen.storyboard b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..ebf48f6 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Base.lproj/Main.storyboard b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Base.lproj/Main.storyboard new file mode 100644 index 0000000..f62accc --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Base.lproj/Main.storyboard @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBBannerView.h b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBBannerView.h new file mode 100644 index 0000000..eb11c16 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBBannerView.h @@ -0,0 +1,19 @@ +// +// EBBannerView.h +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import + +#define BannerStayTime 4.7 +#define BannerAnimationTime 0.3 + +@interface EBBannerView : UIView +@property (nonatomic, retain)NSDictionary *userInfo; +-(void)removeWithAnimation; +@end + +static EBBannerView *SharedBannerView; diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBBannerView.m b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBBannerView.m new file mode 100644 index 0000000..cd46fec --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBBannerView.m @@ -0,0 +1,128 @@ +// +// EBBannerView.m +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. 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 diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBBannerView.xib b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBBannerView.xib new file mode 100644 index 0000000..654cd95 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBBannerView.xib @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBForeNotification.h b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBForeNotification.h new file mode 100644 index 0000000..14ed554 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBForeNotification.h @@ -0,0 +1,193 @@ +// +// EBForeNotification.h +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import + +extern NSString *const EBBannerViewDidClick; //监听点击弹窗的事件 + +@interface EBForeNotification : NSObject ++(void)handleRemoteNotification:(NSDictionary*)userInfo soundID:(int)soundID; ++(void)handleRemoteNotification:(NSDictionary*)userInfo customSound:(NSString*)soundName; +@end + +static NSString *const EBBannerViewTimeText = @"现在"; //默认弹窗时间 default banner time + + +/* + +⭐1.在 AppDelegate.m 中,调用示例如下: + in "AppDelegate.m" call method such as: + + //ios 7 before + - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { + [EBForeNotification handleRemoteNotification:userInfo soundID:1312]; + } + + //ios 7 later + - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { + [EBForeNotification handleRemoteNotification:userInfo soundID:1312]; + completionHandler(UIBackgroundFetchResultNewData); + } + + +⭐2.监听点击弹窗的事件、用户点击以后可以取到推送内容、通过自定义推送中的 extra 字段处理自己的逻辑。如: + add observer for "EBBannerViewDidClick", handle extra key/value + + { + { + aps:"alert":"推送内容", + "sound":"sound", + "badge":"3" + }, + "key1":"跳转页面1" //自定义此字段以跳转到相应页面 + } + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eBBannerViewDidClick:) name:EBBannerViewDidClick object:nil]; + -(void)eBBannerViewDidClick:(NSNotification*)noti{ + if(noti[@"key1" == @"跳转页面1"]){ + //jump to page 1 + } + } + + +⭐3.添加自定义的声音文件并在弹窗时播放 + customSound: u can add a sound file and pass a name like "my_sound.wav" to custom the sound + + +⭐4.使用系统自带声音,默认的推送三全音 id 是 1312 + soundID: is ios system sound id, default push notification sound "Tritone" is 1312 + + Sound ID File name (iPhone) File name (iPod Touch) Category Note + 1000 new-mail.caf new-mail.caf MailReceived + 1001 mail-sent.caf mail-sent.caf MailSent + 1002 Voicemail.caf Voicemail.caf VoicemailReceived + 1003 ReceivedMessage.caf ReceivedMessage.caf SMSReceived + 1004 SentMessage.caf SentMessage.caf SMSSent + 1005 alarm.caf sq_alarm.caf CalendarAlert + 1006 low_power.caf low_power.caf LowPower + 1007 sms-received1.caf sms-received1.caf SMSReceived_Alert + 1008 sms-received2.caf sms-received2.caf SMSReceived_Alert + 1009 sms-received3.caf sms-received3.caf SMSReceived_Alert + 1010 sms-received4.caf sms-received4.caf SMSReceived_Alert + 1011 - - SMSReceived_Vibrate + 1012 sms-received1.caf sms-received1.caf SMSReceived_Alert + 1013 sms-received5.caf sms-received5.caf SMSReceived_Alert + 1014 sms-received6.caf sms-received6.caf SMSReceived_Alert + 1015 Voicemail.caf Voicemail.caf - Available since 2.1 + 1016 tweet_sent.caf tweet_sent.caf SMSSent Available since 5.0 + 1020 Anticipate.caf Anticipate.caf SMSReceived_Alert Available since 4.2 + 1021 Bloom.caf Bloom.caf SMSReceived_Alert Available since 4.2 + 1022 Calypso.caf Calypso.caf SMSReceived_Alert Available since 4.2 + 1023 Choo_Choo.caf Choo_Choo.caf SMSReceived_Alert Available since 4.2 + 1024 Descent.caf Descent.caf SMSReceived_Alert Available since 4.2 + 1025 Fanfare.caf Fanfare.caf SMSReceived_Alert Available since 4.2 + 1026 Ladder.caf Ladder.caf SMSReceived_Alert Available since 4.2 + 1027 Minuet.caf Minuet.caf SMSReceived_Alert Available since 4.2 + 1028 News_Flash.caf News_Flash.caf SMSReceived_Alert Available since 4.2 + 1029 Noir.caf Noir.caf SMSReceived_Alert Available since 4.2 + 1030 Sherwood_Forest.caf Sherwood_Forest.caf SMSReceived_Alert Available since 4.2 + 1031 Spell.caf Spell.caf SMSReceived_Alert Available since 4.2 + 1032 Suspense.caf Suspense.caf SMSReceived_Alert Available since 4.2 + 1033 Telegraph.caf Telegraph.caf SMSReceived_Alert Available since 4.2 + 1034 Tiptoes.caf Tiptoes.caf SMSReceived_Alert Available since 4.2 + 1035 Typewriters.caf Typewriters.caf SMSReceived_Alert Available since 4.2 + 1036 Update.caf Update.caf SMSReceived_Alert Available since 4.2 + 1050 ussd.caf ussd.caf USSDAlert + 1051 SIMToolkitCallDropped.caf SIMToolkitCallDropped.caf SIMToolkitTone + 1052 SIMToolkitGeneralBeep.caf SIMToolkitGeneralBeep.caf SIMToolkitTone + 1053 SIMToolkitNegativeACK.caf SIMToolkitNegativeACK.caf SIMToolkitTone + 1054 SIMToolkitPositiveACK.caf SIMToolkitPositiveACK.caf SIMToolkitTone + 1055 SIMToolkitSMS.caf SIMToolkitSMS.caf SIMToolkitTone + 1057 Tink.caf Tink.caf PINKeyPressed + 1070 ct-busy.caf ct-busy.caf AudioToneBusy There was no category for this sound before 4.0. + 1071 ct-congestion.caf ct-congestion.caf AudioToneCongestion There was no category for this sound before 4.0. + 1072 ct-path-ack.caf ct-path-ack.caf AudioTonePathAcknowledge There was no category for this sound before 4.0. + 1073 ct-error.caf ct-error.caf AudioToneError There was no category for this sound before 4.0. + 1074 ct-call-waiting.caf ct-call-waiting.caf AudioToneCallWaiting There was no category for this sound before 4.0. + 1075 ct-keytone2.caf ct-keytone2.caf AudioToneKey2 There was no category for this sound before 4.0. + 1100 lock.caf sq_lock.caf ScreenLocked + 1101 unlock.caf sq_lock.caf ScreenUnlocked + 1102 - - FailedUnlock + 1103 Tink.caf sq_tock.caf KeyPressed + 1104 Tock.caf sq_tock.caf KeyPressed + 1105 Tock.caf sq_tock.caf KeyPressed + 1106 beep-beep.caf sq_beep-beep.caf ConnectedToPower + 1107 RingerChanged.caf RingerChanged.caf RingerSwitchIndication + 1108 photoShutter.caf photoShutter.caf CameraShutter + 1109 shake.caf shake.caf ShakeToShuffle Available since 3.0 + 1110 jbl_begin.caf jbl_begin.caf JBL_Begin Available since 3.0 + 1111 jbl_confirm.caf jbl_confirm.caf JBL_Confirm Available since 3.0 + 1112 jbl_cancel.caf jbl_cancel.caf JBL_Cancel Available since 3.0 + 1113 begin_record.caf begin_record.caf BeginRecording Available since 3.0 + 1114 end_record.caf end_record.caf EndRecording Available since 3.0 + 1115 jbl_ambiguous.caf jbl_ambiguous.caf JBL_Ambiguous Available since 3.0 + 1116 jbl_no_match.caf jbl_no_match.caf JBL_NoMatch Available since 3.0 + 1117 begin_video_record.caf begin_video_record.caf BeginVideoRecording Available since 3.0 + 1118 end_video_record.caf end_video_record.caf EndVideoRecording Available since 3.0 + 1150 vc~invitation-accepted.caf vc~invitation-accepted.caf VCInvitationAccepted Available since 4.0 + 1151 vc~ringing.caf vc~ringing.caf VCRinging Available since 4.0 + 1152 vc~ended.caf vc~ended.caf VCEnded Available since 4.0 + 1153 ct-call-waiting.caf ct-call-waiting.caf VCCallWaiting Available since 4.1 + 1154 vc~ringing.caf vc~ringing.caf VCCallUpgrade Available since 4.1 + 1200 dtmf-0.caf dtmf-0.caf TouchTone + 1201 dtmf-1.caf dtmf-1.caf TouchTone + 1202 dtmf-2.caf dtmf-2.caf TouchTone + 1203 dtmf-3.caf dtmf-3.caf TouchTone + 1204 dtmf-4.caf dtmf-4.caf TouchTone + 1205 dtmf-5.caf dtmf-5.caf TouchTone + 1206 dtmf-6.caf dtmf-6.caf TouchTone + 1207 dtmf-7.caf dtmf-7.caf TouchTone + 1208 dtmf-8.caf dtmf-8.caf TouchTone + 1209 dtmf-9.caf dtmf-9.caf TouchTone + 1210 dtmf-star.caf dtmf-star.caf TouchTone + 1211 dtmf-pound.caf dtmf-pound.caf TouchTone + 1254 long_low_short_high.caf long_low_short_high.caf Headset_StartCall + 1255 short_double_high.caf short_double_high.caf Headset_Redial + 1256 short_low_high.caf short_low_high.caf Headset_AnswerCall + 1257 short_double_low.caf short_double_low.caf Headset_EndCall + 1258 short_double_low.caf short_double_low.caf Headset_CallWaitingActions + 1259 middle_9_short_double_low.caf middle_9_short_double_low.caf Headset_TransitionEnd + 1300 Voicemail.caf Voicemail.caf SystemSoundPreview + 1301 ReceivedMessage.caf ReceivedMessage.caf SystemSoundPreview + 1302 new-mail.caf new-mail.caf SystemSoundPreview + 1303 mail-sent.caf mail-sent.caf SystemSoundPreview + 1304 alarm.caf sq_alarm.caf SystemSoundPreview + 1305 lock.caf sq_lock.caf SystemSoundPreview + 1306 Tock.caf sq_tock.caf KeyPressClickPreview The category was SystemSoundPreview before 3.2. + 1307 sms-received1.caf sms-received1.caf SMSReceived_Selection + 1308 sms-received2.caf sms-received2.caf SMSReceived_Selection + 1309 sms-received3.caf sms-received3.caf SMSReceived_Selection + 1310 sms-received4.caf sms-received4.caf SMSReceived_Selection + 1311 - - SMSReceived_Vibrate + 1312 sms-received1.caf sms-received1.caf SMSReceived_Selection + 1313 sms-received5.caf sms-received5.caf SMSReceived_Selection + 1314 sms-received6.caf sms-received6.caf SMSReceived_Selection + 1315 Voicemail.caf Voicemail.caf SystemSoundPreview Available since 2.1 + 1320 Anticipate.caf Anticipate.caf SMSReceived_Selection Available since 4.2 + 1321 Bloom.caf Bloom.caf SMSReceived_Selection Available since 4.2 + 1322 Calypso.caf Calypso.caf SMSReceived_Selection Available since 4.2 + 1323 Choo_Choo.caf Choo_Choo.caf SMSReceived_Selection Available since 4.2 + 1324 Descent.caf Descent.caf SMSReceived_Selection Available since 4.2 + 1325 Fanfare.caf Fanfare.caf SMSReceived_Selection Available since 4.2 + 1326 Ladder.caf Ladder.caf SMSReceived_Selection Available since 4.2 + 1327 Minuet.caf Minuet.caf SMSReceived_Selection Available since 4.2 + 1328 News_Flash.caf News_Flash.caf SMSReceived_Selection Available since 4.2 + 1329 Noir.caf Noir.caf SMSReceived_Selection Available since 4.2 + 1330 Sherwood_Forest.caf Sherwood_Forest.caf SMSReceived_Selection Available since 4.2 + 1331 Spell.caf Spell.caf SMSReceived_Selection Available since 4.2 + 1332 Suspense.caf Suspense.caf SMSReceived_Selection Available since 4.2 + 1333 Telegraph.caf Telegraph.caf SMSReceived_Selection Available since 4.2 + 1334 Tiptoes.caf Tiptoes.caf SMSReceived_Selection Available since 4.2 + 1335 Typewriters.caf Typewriters.caf SMSReceived_Selection Available since 4.2 + 1336 Update.caf Update.caf SMSReceived_Selection Available since 4.2 + 1350 - - RingerVibeChanged + 1351 - - SilentVibeChanged + 4095 - - Vibrate There was no category for this sound before 2.2. + In the SDK this is the constant kSystemSoundID_Vibrate. + + */ \ No newline at end of file diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBForeNotification.m b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBForeNotification.m new file mode 100644 index 0000000..ec01d4a --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBForeNotification.m @@ -0,0 +1,71 @@ +// +// EBForeNotification.m +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import "EBForeNotification.h" +#import +#import +#import "EBBannerView.h" +#import "UIViewController+EBForeNotification.h" + +NSString *const EBBannerViewDidClick = @"EBBannerViewDidClick"; + +@implementation EBForeNotification + +#pragma mark - public + ++(void)handleRemoteNotification:(NSDictionary*)userInfo soundID:(int)soundID{ + if (userInfo) { + [EBBannerView class]; + id aps = [userInfo valueForKey:@"aps"]; + if (aps && [aps isKindOfClass:[NSDictionary class]] && [aps valueForKey:@"alert"] && ![[aps valueForKey:@"alert"] isEqual: @""]) { + [EBForeNotification showBannerWithUserInfo:userInfo soundID:soundID]; + } + } +} + ++(void)handleRemoteNotification:(NSDictionary*)userInfo customSound:(NSString*)soundName{ + if (soundName) { + NSURL *url = [[NSBundle mainBundle] URLForResource:soundName withExtension:nil]; + SystemSoundID soundID = 0; + AudioServicesCreateSystemSoundID((__bridge CFURLRef)(url), &soundID); + [EBForeNotification handleRemoteNotification:userInfo soundID:soundID]; + } +} + +#pragma mark - private + ++(void)showBannerWithUserInfo:(NSDictionary*)userInfo soundID:(int)soundID{ + if (soundID) { + AudioServicesPlaySystemSound(soundID); + } + if (SharedBannerView) { + SharedBannerView = nil; + } + SharedBannerView = [[NSBundle mainBundle] loadNibNamed:@"EBBannerView" owner:nil options:nil].lastObject; + UIViewController *controller = [EBForeNotification appRootViewController]; + SharedBannerView.userInfo = userInfo; + [controller.view addSubview:SharedBannerView]; + [NSTimer scheduledTimerWithTimeInterval:BannerStayTime target:self selector:@selector(deleteBanner) userInfo:nil repeats:NO]; +} + ++(UIViewController *)appRootViewController{ + UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController; + UIViewController *topVC = appRootVC; + while (topVC.presentedViewController) { + topVC = topVC.presentedViewController; + } + return topVC; +} + ++(void)deleteBanner{ + if (SharedBannerView) { + [SharedBannerView removeWithAnimation]; + } +} + +@end diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Info.plist b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Info.plist new file mode 100644 index 0000000..77c7282 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/Info.plist @@ -0,0 +1,40 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + QQ + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/UIImage+ColorAtPoint.h b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/UIImage+ColorAtPoint.h new file mode 100644 index 0000000..00c84bd --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/UIImage+ColorAtPoint.h @@ -0,0 +1,13 @@ +// +// UIImage+ColorAtPoint.h +// EBForeNotification +// +// Created by wuxingchen on 16/7/22. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import + +@interface UIImage (ColorAtPoint) ++(UIColor *)colorAtPoint:(CGPoint)point; +@end diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/UIImage+ColorAtPoint.m b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/UIImage+ColorAtPoint.m new file mode 100644 index 0000000..96e091e --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/UIImage+ColorAtPoint.m @@ -0,0 +1,90 @@ +// +// UIImage+ColorAtPoint.m +// EBForeNotification +// +// Created by wuxingchen on 16/7/22. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import "UIImage+ColorAtPoint.h" + +@implementation UIImage (ColorAtPoint) + ++(UIColor *)colorAtPoint:(CGPoint)point{ + UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow]; + UIGraphicsBeginImageContext(screenWindow.frame.size);//全屏截图,包括window + + [screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()]; + + UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); + + + if (!CGRectContainsPoint(CGRectMake(0.0f, 0.0f, viewImage.size.width, viewImage.size.height), point)) { + + return nil; + + } + + + NSInteger pointX = trunc(point.x); + + NSInteger pointY = trunc(point.y); + + CGImageRef cgImage = viewImage.CGImage; + + NSUInteger width = viewImage.size.width; + + NSUInteger height = viewImage.size.height; + + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + int bytesPerPixel = 4; + + int bytesPerRow = bytesPerPixel * 1; + + NSUInteger bitsPerComponent = 8; + + unsigned char pixelData[4] = { 0, 0, 0, 0 }; + + CGContextRef context = CGBitmapContextCreate(pixelData, + + 1, + + 1, + + bitsPerComponent, + + bytesPerRow, + + colorSpace, + + kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); + + CGColorSpaceRelease(colorSpace); + + CGContextSetBlendMode(context, kCGBlendModeCopy); + + + // Draw the pixel we are interested in onto the bitmap context + + CGContextTranslateCTM(context, -pointX, pointY-(CGFloat)height); + + CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, (CGFloat)width, (CGFloat)height), cgImage); + + CGContextRelease(context); + + // Convert color values [0..255] to floats [0.0..1.0] + + CGFloat red = (CGFloat)pixelData[0] / 255.0f; + + CGFloat green = (CGFloat)pixelData[1] / 255.0f; + + CGFloat blue = (CGFloat)pixelData[2] / 255.0f; + + CGFloat alpha = (CGFloat)pixelData[3] / 255.0f; + + return [UIColor colorWithRed:red green:green blue:blue alpha:alpha]; +} + + +@end diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/UIViewController+EBForeNotification.h b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/UIViewController+EBForeNotification.h new file mode 100644 index 0000000..6430f45 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/UIViewController+EBForeNotification.h @@ -0,0 +1,13 @@ +// +// UIViewController+EBForeNotification.h +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import + +@interface UIViewController (EBForeNotification) +@property(nonatomic, assign)BOOL EBForegroundNotificationStatusBarHidden; +@end diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/UIViewController+EBForeNotification.m b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/UIViewController+EBForeNotification.m new file mode 100644 index 0000000..aa9cfa5 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/UIViewController+EBForeNotification.m @@ -0,0 +1,33 @@ +// +// UIViewController+EBForeNotification.m +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import "UIViewController+EBForeNotification.h" +#import + +@implementation UIViewController (EBForeNotification) + +static BOOL _EBForegroundNotificationStatusBarHidden; + +- (void)setEBForegroundNotificationStatusBarHidden:(BOOL)EBForegroundNotificationStatusBarHidden{ + NSNumber *t = @(EBForegroundNotificationStatusBarHidden); + objc_setAssociatedObject(self, &_EBForegroundNotificationStatusBarHidden, t, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + [self setNeedsStatusBarAppearanceUpdate]; +} + +- (BOOL)EBForegroundNotificationStatusBarHidden{ + NSNumber *t = objc_getAssociatedObject(self, &_EBForegroundNotificationStatusBarHidden); + return [t boolValue]; +} + +#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation" +-(BOOL)prefersStatusBarHidden{ + return self.EBForegroundNotificationStatusBarHidden; +} + +@end + diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/ViewController.h b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/ViewController.h new file mode 100644 index 0000000..a9b0d6b --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/ViewController.h @@ -0,0 +1,15 @@ +// +// ViewController.h +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import + +@interface ViewController : UIViewController + + +@end + diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/ViewController.m b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/ViewController.m new file mode 100644 index 0000000..34cb308 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/ViewController.m @@ -0,0 +1,33 @@ +// +// ViewController.m +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import "ViewController.h" +#import "EBForeNotification.h" + +@interface ViewController () + +@end + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(aaaaaa) userInfo:nil repeats:NO]; +} + +-(void)aaaaaa{ + [EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":@"皮卡丘:Hi 小智,一起去冒险吧!"}} soundID:1312]; +} + + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +@end diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/main.m b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/main.m new file mode 100644 index 0000000..522ad6d --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/main.m @@ -0,0 +1,16 @@ +// +// main.m +// iOS-Foreground-Push-Notification +// +// Created by wuxingchen on 16/7/21. +// Copyright © 2016年 57380422@qq.com. All rights reserved. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/node_modules/one-line-jpush-ios/README.md b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/node_modules/one-line-jpush-ios/README.md new file mode 100644 index 0000000..8646144 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/node_modules/one-line-jpush-ios/README.md @@ -0,0 +1,12 @@ +# one-line-jpush-native +one line jpush for ios + +### 只需一行命令 +- 自动下载 JPush 插件 +- 自动安装插件 +- 自动添加必须类库 +- 自动写入必须代码 +- 立刻开始推送! + +### 详细说明见此 +[http://www.jianshu.com/p/396ae5ade33f](http://www.jianshu.com/p/396ae5ade33f) diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/node_modules/one-line-jpush-ios/iOS SDK API.webloc b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/node_modules/one-line-jpush-ios/iOS SDK API.webloc new file mode 100644 index 0000000..4817ee2 --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/node_modules/one-line-jpush-ios/iOS SDK API.webloc @@ -0,0 +1,8 @@ + + + + + URL + http://docs.jpush.io/client/ios_api/ + + diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/node_modules/one-line-jpush-ios/install_jpush.rb b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/node_modules/one-line-jpush-ios/install_jpush.rb new file mode 100644 index 0000000..07390bc --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/node_modules/one-line-jpush-ios/install_jpush.rb @@ -0,0 +1,479 @@ +#!/usr/bin/env ruby + + +system("echo Checking ...") +print "xcodeproj version: " +xcodeproj = system("xcodeproj --version") + +if !xcodeproj + system("echo Downloading ...") + system("sudo gem install xcodeproj") +end + +require 'xcodeproj' +require 'open-uri' +require 'fileutils' +require 'find' + +module Xcodeproj + class Project + module Object + class AbstractTarget < AbstractObject + def add_system_library_tbd(names) + Array(names).each do |name| + path = "usr/lib/lib#{name}.tbd" + files = project.frameworks_group.files + unless reference = files.find { |ref| ref.path == path } + reference = project.frameworks_group.new_file(path, :sdk_root) + end + frameworks_build_phase.add_file_reference(reference, true) + reference + end + end + + end + end +end +end + +## ########################### install_native ########################### + +def install_native + + appkey = ARGV[0] + + src_dir = Dir.getwd + src_dir[-32,src_dir.length] = "" + Dir.chdir(src_dir) + jpush_sdk_d = src_dir + "/jpush_sdk" + + + ## download + open('jpush_sdk.zip', 'wb') do |file| + puts "Downloading JPush SDK ..." + file << open('https://sdkfiledl.jiguang.cn/JPush-iOS-SDK-2.1.8.zip').read + system("mkdir jpush_sdk") + FileUtils.mv file,jpush_sdk_d + end + + + ## zip move delete + system("unzip -o #{jpush_sdk_d+"/jpush_sdk"} -d #{jpush_sdk_d}") + system("mv #{jpush_sdk_d+"/JPush-iOS-SDK-2.1.8/lib/jpush-ios-2.1.8.a"} #{jpush_sdk_d+"/"}") + system("mv #{jpush_sdk_d+"/JPush-iOS-SDK-2.1.8/lib/JPUSHService.h"} #{jpush_sdk_d+"/"}") + system("rm -rf #{jpush_sdk_d+"/__MACOSX"}") + system("rm -rf #{jpush_sdk_d+"/JPush-iOS-SDK-2.1.8"}") + system("rm -rf #{jpush_sdk_d+"/jpush_sdk.zip"}") + + ## xcode version + + xcode_version_path = "/Applications/Xcode.app/Contents/version.plist" + + xcode_version = 0 + + if File.exists?(xcode_version_path) + find = 0 + open(xcode_version_path,"r") do |file| + file.each_line do |line| + if find == 1 + xcode_version = line.delete("").delete("") + puts "Xcode version:#{xcode_version}" + while(xcode_version.length > 4) + xcode_version = xcode_version.chop + end + break + end + if line.include?"CFBundleShortVersionString" + find = 1 + end + end + end + else + puts "Please install Xcode under the directory '/Applications/' " + exit + end + + ## add framework + + project = Xcodeproj::Project.open(src_dir+".xcodeproj") + + target = project.targets.first + + group = project.main_group.find_subpath(File.join('jpush_sdk'), true) + + group.set_source_tree('SOURCE_ROOT') + + file_ref1 = group.new_reference(jpush_sdk_d+"/jpush-ios-2.1.8.a") + file_ref2 = group.new_reference(jpush_sdk_d+"/JPUSHService.h") + + target.frameworks_build_phase.add_file_reference(file_ref1, true) + target.add_file_references([file_ref2]) + + target.add_system_frameworks("CFNetwork") + target.add_system_frameworks("CoreFoundation") + target.add_system_frameworks("CoreTelephony") + target.add_system_frameworks("CoreGraphics") + target.add_system_frameworks("Foundation") + target.add_system_frameworks("UIKit") + target.add_system_frameworks("Security") + target.add_system_frameworks("SystemConfiguration") + if xcode_version.to_i >= 7 + target.add_system_library_tbd("z") + else + target.add_system_library("z") + end + target.add_system_frameworks("AdSupport") + + project.save + + ## add code + + appDelegate_path = "" + + def searchFor(name) + Find.find(Dir.getwd) do |filename| + if filename.include?name + return filename + end + end + end + + appDelegate_path = searchFor("AppDelegate.m") + + open(appDelegate_path+"m","w") do |test| + open(appDelegate_path, 'r') do |file| + file.each_line do |line| + if line.start_with?('#import "AppDelegate.h"') + test.print line + test.print '#import "JPUSHService.h"' + test.print "\n" + + elsif line.start_with?("- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {") + + + test.puts "\ +- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{ \n\ + // JPush sdk \n\ + [JPUSHService registerDeviceToken:deviceToken]; \n\ +}" + + test.puts "\n" + test.puts "\ +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { \n\ + // JPush sdk \n\ + [JPUSHService handleRemoteNotification:userInfo]; \n\ +}" + test.print "\n" + + + test.puts "\ +//IOS7 only \n\ +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { \n\ + [JPUSHService handleRemoteNotification:userInfo]; \n\ + completionHandler(UIBackgroundFetchResultNewData); \n\ +}" + test.print "\n" + + + test.print line + test.print " //JPush sdk" + test.print "\n" + test.print ' [JPUSHService setupWithOption:launchOptions appKey:@"'+appkey+'" channel:@"" apsForProduction:NO advertisingIdentifier:nil];' + test.puts "\n\n\n" + + + test.puts "\ +#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1 \n\ + if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { \n\ + //可以添加自定义categories \n\ + [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | \n\ + UIUserNotificationTypeSound | \n\ + UIUserNotificationTypeAlert) \n\ + categories:nil]; \n\ + } else { \n\ + //categories 必须为nil \n\ + [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | \n\ + UIRemoteNotificationTypeSound | \n\ + UIRemoteNotificationTypeAlert) \n\ + categories:nil]; \n\ + } \n\ +#else \n\ + //categories 必须为nil \n\ + [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | \n\ + UIRemoteNotificationTypeSound | \n\ + UIRemoteNotificationTypeAlert) \n\ + categories:nil]; \n\ +#endif \n" + + + else + test.print line + end + end + end + end + + File.open(appDelegate_path,"w") do |test| + File.open(appDelegate_path+"m",'r') do |file| + file.each_line do | line| + test.print line + end + end + end + + system("rm -rf #{appDelegate_path+"m"}") + +end + + +## ########################### install_cocos2dx ########################### + +def install_cocos2dx + + src_dir = Dir.getwd + "/../../" + jpush_sdk_d = src_dir + "jpush_sdk" + appkey = ARGV[1] + + ## download + open('jpush_sdk.zip', 'wb') do |file| + puts "Downloading JPush SDK ..." + file << open('https://www.jpush.cn/downloads/sdk/ios8/').read + system("mkdir #{jpush_sdk_d+"/"}") + FileUtils.mv file,jpush_sdk_d + end + + open('JPushBridge.h','wb') do |file| + puts "Downloading JPushBridge.h ..." + file << open('https://raw.githubusercontent.com/jpush/jpush-cocos2d-x-plugin/master/iOS/JPushPlugin/JPushBridge.h').read + FileUtils.mv file,jpush_sdk_d + end + + open('JPushBridge.mm','wb') do |file| + puts "Downloading JPushBridge.mm ..." + file << open('https://raw.githubusercontent.com/jpush/jpush-cocos2d-x-plugin/master/iOS/JPushPlugin/JPushBridge.mm').read + FileUtils.mv file,jpush_sdk_d + end + + + ## zip move delete + system("unzip -o #{jpush_sdk_d+"/jpush_sdk"} -d #{jpush_sdk_d}") + system("mv #{jpush_sdk_d+"/JPush-iOS-SDK-2.1.8/lib/jpush-ios-2.1.8.a"} #{jpush_sdk_d+"/"}") + system("mv #{jpush_sdk_d+"/JPush-iOS-SDK-2.1.8/lib/JPUSHService.h"} #{jpush_sdk_d+"/"}") + system("rm -rf #{jpush_sdk_d+"/__MACOSX"}") + system("rm -rf #{jpush_sdk_d+"/JPush-iOS-SDK-2.1.8"}") + system("rm -rf #{jpush_sdk_d+"/jpush_sdk.zip"}") + + ## xcode version + + xcode_version_path = "/Applications/Xcode.app/Contents/version.plist" + + xcode_version = 0 + + if File.exists?(xcode_version_path) + find = 0 + open(xcode_version_path,"r") do |file| + file.each_line do |line| + if find == 1 + xcode_version = line.delete("").delete("") + puts "Xcode version:#{xcode_version}" + while(xcode_version.length > 4) + xcode_version = xcode_version.chop + end + break + end + if line.include?"CFBundleShortVersionString" + find = 1 + end + end + end + else + puts "Please install Xcode under the directory '/Applications/' " + exit + end + + ## add framework + + def searchForProjectDir(name) + Find.find(Dir.getwd+"/../../") do |filename| + if filename.include?name + return filename + end + end + end + project_dir = searchForProjectDir(".xcodeproj") + + project = Xcodeproj::Project.open(project_dir) + + target = project.targets.first + + group = project.main_group.find_subpath(File.join('jpush_sdk'), true) + + group.set_source_tree('SOURCE_ROOT') + + file_ref1 = group.new_reference(jpush_sdk_d+"/jpush-ios-2.1.8.a") + file_ref2 = group.new_reference(jpush_sdk_d+"/JPUSHService.h") + file_ref3 = group.new_reference(jpush_sdk_d+"/JPushBridge.h") + file_ref4 = group.new_reference(jpush_sdk_d+"/JPushBridge.mm") + + target.frameworks_build_phase.add_file_reference(file_ref1, true) + target.add_file_references([file_ref2]) + target.add_file_references([file_ref3]) + target.add_file_references([file_ref4]) + + target.add_system_frameworks("CFNetwork") + target.add_system_frameworks("CoreFoundation") + target.add_system_frameworks("CoreTelephony") + target.add_system_frameworks("CoreGraphics") + target.add_system_frameworks("Foundation") + target.add_system_frameworks("UIKit") + target.add_system_frameworks("Security") + target.add_system_frameworks("SystemConfiguration") + if xcode_version.to_i >= 7 + target.add_system_library_tbd("z") + else + target.add_system_library("z") + end + target.add_system_frameworks("AdSupport") + + project.save + + ## add code + + def searchFor(name) + Find.find(Dir.getwd+"/../../") do |filename| + puts filename + if filename.include?name + return filename + end + end + end + + appDelegate_path = "" + + appDelegate_path = searchFor("AppController.mm") + + appDelegate_path_temp = appDelegate_path + + appDelegate_path_temp = appDelegate_path_temp.chop + + open(appDelegate_path_temp,"w") do |test| + open(appDelegate_path, 'r') do |file| + file.each_line do |line| + if line.start_with?('#import "AppDelegate.h"') + test.print line + test.print '#import "JPUSHService.h"' + test.print "\n" + elsif line.start_with?("- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {") + + + test.puts "\ +- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{ \n\ + // JPush sdk \n\ + [JPUSHService registerDeviceToken:deviceToken]; \n\ +}" + + test.puts "\n" + test.puts "\ +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { \n\ + // JPush sdk \n\ + [JPUSHService handleRemoteNotification:userInfo]; \n\ +}" + test.print "\n" + + + test.puts "\ +//IOS7 only \n\ +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { \n\ + [JPUSHService handleRemoteNotification:userInfo]; \n\ + completionHandler(UIBackgroundFetchResultNewData); \n\ +}" + test.print "\n" + + test.print line + + test.print " //JPush sdk" + test.print "\n" + test.print ' [JPUSHService setupWithOption:launchOptions appKey:@"'+appkey+'" channel:@"" apsForProduction:NO advertisingIdentifier:nil];' + test.puts "\n\n\n" + + + test.puts "\ +#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1 \n\ + if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { \n\ + //可以添加自定义categories \n\ + [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | \n\ + UIUserNotificationTypeSound | \n\ + UIUserNotificationTypeAlert) \n\ + categories:nil]; \n\ + } else { \n\ + //categories 必须为nil \n\ + [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | \n\ + UIRemoteNotificationTypeSound | \n\ + UIRemoteNotificationTypeAlert) \n\ + categories:nil]; \n\ + } \n\ +#else \n\ + //categories 必须为nil \n\ + [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | \n\ + UIRemoteNotificationTypeSound | \n\ + UIRemoteNotificationTypeAlert) \n\ + categories:nil]; \n\ +#endif \n" + + else + test.print line + end + end + end + end + + File.open(appDelegate_path,"w") do |test| + File.open(appDelegate_path_temp,'r') do |file| + file.each_line do | line| + test.print line + end + end + end + + system("rm -rf #{appDelegate_path_temp}") + +end + +## ########################### install_cordova ########################### + +def install_cordova + appkey = ARGV[0] + system("cordova platform add ios") + system("cordova plugin add cordova-plugin-device") + system("cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=#{appkey}") +end + +## ########################### def end ########################### + +appkey = ARGV[0] +puts "-----"+"appkey:"+appkey+"-----" + +platform = ARGV[1] +if !platform + platform = "native" +end +puts "-----"+"platform:"+platform+"-----" + +if platform == "native" + install_native() +elsif platform == "cocos2dx" + install_cocos2dx() +elsif platform == "cordova" + install_cordova() +elsif + install_native() +end + +puts "-----------------------------------------------------------" +puts "JPush SDK installed successfully, have fun!" +puts "appkey: #{appkey}" +puts "platform: #{platform}" +puts "-----------------------------------------------------------" +puts "" + +exit diff --git a/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/node_modules/one-line-jpush-ios/package.json b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/node_modules/one-line-jpush-ios/package.json new file mode 100644 index 0000000..e1a44df --- /dev/null +++ b/demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/node_modules/one-line-jpush-ios/package.json @@ -0,0 +1,87 @@ +{ + "_args": [ + [ + "one-line-jpush-ios", + "/Users/wuxingchen/Desktop/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification" + ] + ], + "_from": "one-line-jpush-ios@latest", + "_id": "one-line-jpush-ios@1.0.70", + "_inCache": true, + "_installable": true, + "_location": "/one-line-jpush-ios", + "_nodeVersion": "5.6.0", + "_npmOperationalInternal": { + "host": "packages-16-east.internal.npmjs.com", + "tmp": "tmp/one-line-jpush-ios-1.0.70.tgz_1469078804589_0.2880012996029109" + }, + "_npmUser": { + "email": "pikacode@qq.com", + "name": "pikacode" + }, + "_npmVersion": "3.6.0", + "_phantomChildren": {}, + "_requested": { + "name": "one-line-jpush-ios", + "raw": "one-line-jpush-ios", + "rawSpec": "", + "scope": null, + "spec": "latest", + "type": "tag" + }, + "_requiredBy": [ + "#USER" + ], + "_shasum": "7df7335753009794ea24d7be44a0305406e0a4e5", + "_shrinkwrap": null, + "_spec": "one-line-jpush-ios", + "_where": "/Users/wuxingchen/Desktop/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification", + "author": { + "name": "pikacode@qq.com" + }, + "bugs": { + "url": "https://github.com/Yasashi/one-line-jpush-native/issues" + }, + "dependencies": {}, + "description": "一行命令集成 极光推送(iOS)", + "devDependencies": {}, + "directories": {}, + "dist": { + "shasum": "7df7335753009794ea24d7be44a0305406e0a4e5", + "tarball": "https://registry.npmjs.org/one-line-jpush-ios/-/one-line-jpush-ios-1.0.70.tgz" + }, + "files": [ + "README.md", + "iOS SDK API.webloc", + "install_jpush.rb", + "npm-debug.log" + ], + "homepage": "https://github.com/Yasashi/one-line-jpush-native#README.md", + "keywords": [ + "cocos2d-x", + "ios", + "jpush", + "native", + "one-line", + "phonegap" + ], + "license": "ISC", + "main": "index.js", + "maintainers": [ + { + "name": "pikacode", + "email": "pikacode@qq.com" + } + ], + "name": "one-line-jpush-ios", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/Yasashi/one-line-jpush-native.git" + }, + "scripts": { + "install": "ruby install_jpush.rb $appkey $platform" + }, + "version": "1.0.70" +}