Skip to content

Commit 16af1c1

Browse files
committed
update
1 parent ad74a14 commit 16af1c1

File tree

15 files changed

+217
-43
lines changed

15 files changed

+217
-43
lines changed

EBForeNotification.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "EBForeNotification"
19-
s.version = "1.0.6"
19+
s.version = "1.0.7"
2020
s.summary = "iOS 前台推送及事件处理。iOS Foreground Push Notification and event-handle."
2121

2222
# This description is used to generate tags and improve search results.
@@ -109,7 +109,7 @@ Pod::Spec.new do |s|
109109
#
110110

111111
# s.resource = "icon.png"
112-
s.resources = "EBForeNotification/Classes/*.xib"
112+
s.resources = "EBForeNotification/Classes/*.{xib,mp3}"
113113

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

EBForeNotification/Classes/EBForeNotification.m

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,14 @@
1111
#import <UIKit/UIKit.h>
1212
#import "EBBannerView.h"
1313
#import "UIImage+ColorAtPoint.h"
14-
14+
#import "EBMuteDetector.h"
1515

1616
NSString *const EBBannerViewDidClick = @"EBBannerViewDidClick";
1717

1818
@implementation EBForeNotification
1919

2020
#pragma mark - public
2121

22-
+(void)handleRemoteNotification:(NSDictionary*)userInfo soundID:(int)soundID isIos10:(BOOL)isIos10{
23-
if (userInfo) {
24-
id aps = [userInfo valueForKey:@"aps"];
25-
if (aps && [aps isKindOfClass:[NSDictionary class]] && [aps valueForKey:@"alert"] && ![[aps valueForKey:@"alert"] isEqual: @""]) {
26-
[EBForeNotification showBannerWithUserInfo:userInfo soundID:soundID isIos10:isIos10];
27-
}
28-
}
29-
}
30-
3122
+(void)handleRemoteNotification:(NSDictionary*)userInfo soundID:(int)soundID{
3223
[EBForeNotification handleRemoteNotification:userInfo soundID:soundID isIos10:NO];
3324
}
@@ -45,11 +36,26 @@ +(void)handleRemoteNotification:(NSDictionary*)userInfo customSound:(NSString*)s
4536
}
4637
}
4738

39+
+(void)handleRemoteNotification:(NSDictionary*)userInfo soundID:(int)soundID isIos10:(BOOL)isIos10{
40+
if (userInfo) {
41+
id aps = [userInfo valueForKey:@"aps"];
42+
if (aps && [aps isKindOfClass:[NSDictionary class]] && [aps valueForKey:@"alert"] && ![[aps valueForKey:@"alert"] isEqual: @""]) {
43+
[EBForeNotification showBannerWithUserInfo:userInfo soundID:soundID isIos10:isIos10];
44+
}
45+
}
46+
}
47+
4848
#pragma mark - private
4949

5050
+(void)showBannerWithUserInfo:(NSDictionary*)userInfo soundID:(int)soundID isIos10:(BOOL)isIos10{
5151
if (soundID) {
52-
AudioServicesPlaySystemSound(soundID);
52+
[[EBMuteDetector sharedDetecotr] detectComplete:^(BOOL isMute) {
53+
if (isMute) {
54+
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
55+
}else{
56+
AudioServicesPlaySystemSound(soundID);
57+
}
58+
}];
5359
}
5460
if (SharedBannerView) {
5561
SharedBannerView = nil;
1.67 KB
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// EBMuteSwitchDetector.h
3+
//
4+
// Created by [email protected] on 6/2/13.
5+
// Copyright (c) 2013 [email protected]. All rights reserved.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
10+
@interface EBMuteDetector : NSObject
11+
12+
+(EBMuteDetector*)sharedDetecotr;
13+
14+
-(void)detectComplete:(void (^)(BOOL isMute))completionHandler;
15+
16+
@end
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// EBMuteSwitchDetector.m
3+
//
4+
// Created by [email protected] 6/2/13.
5+
// Copyright (c) 2013 [email protected]. All rights reserved.
6+
//
7+
8+
#import "EBMuteDetector.h"
9+
#import <AudioToolbox/AudioToolbox.h>
10+
#import <UIKit/UIKit.h>
11+
12+
@interface EBMuteDetector()
13+
14+
@property (nonatomic,assign) NSTimeInterval interval;
15+
16+
@property (nonatomic,assign) SystemSoundID soundId;
17+
18+
19+
typedef void (^DetectCompleteBlock)(BOOL isMute);
20+
21+
@property(nonatomic, copy)DetectCompleteBlock completeBlock;
22+
23+
@end
24+
25+
@implementation EBMuteDetector
26+
27+
void EBSoundMuteNotificationCompletionProc(SystemSoundID ssID,void* clientData){
28+
NSTimeInterval elapsed = [NSDate timeIntervalSinceReferenceDate] - [EBMuteDetector sharedDetecotr].interval;
29+
BOOL isMute = elapsed < 0.1;
30+
[EBMuteDetector sharedDetecotr].completeBlock(isMute);
31+
}
32+
33+
+(EBMuteDetector*)sharedDetecotr{
34+
static EBMuteDetector* sharedDetecotr = nil;
35+
static dispatch_once_t onceToken;
36+
dispatch_once(&onceToken, ^{
37+
sharedDetecotr = [EBMuteDetector new];
38+
NSURL* url = [[NSBundle bundleForClass:[self class]] URLForResource:@"EBMute" withExtension:@"mp3"];
39+
if (AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &sharedDetecotr->_soundId) == kAudioServicesNoError){
40+
AudioServicesAddSystemSoundCompletion(sharedDetecotr.soundId, CFRunLoopGetMain(), kCFRunLoopDefaultMode, EBSoundMuteNotificationCompletionProc,(__bridge void *)(self));
41+
UInt32 yes = 1;
42+
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(sharedDetecotr.soundId),&sharedDetecotr->_soundId,sizeof(yes), &yes);
43+
} else {
44+
sharedDetecotr.soundId = -1;
45+
}
46+
});
47+
return sharedDetecotr;
48+
}
49+
50+
-(void)detectComplete:(void (^)(BOOL isMute))completionHandler{
51+
self.interval = [NSDate timeIntervalSinceReferenceDate];
52+
AudioServicesPlaySystemSound(self.soundId);
53+
self.completeBlock = completionHandler;
54+
}
55+
56+
-(void)dealloc{
57+
if (self.soundId != -1){
58+
AudioServicesRemoveSystemSoundCompletion(self.soundId);
59+
AudioServicesDisposeSystemSoundID(self.soundId);
60+
}
61+
}
62+
63+
@end

EBForeNotification/EBForeNotification.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
//
2-
// EBForeNotification.h
3-
// iOS-Foreground-Push-Notification
4-
//
5-
// Created by wuxingchen on 16/7/21.
1+
62
// Copyright © 2016年 [email protected]. All rights reserved.
7-
//
3+
4+
// version 1.0.7
85

96
#import <Foundation/Foundation.h>
107

demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
0901F52012465E429D4C4EF8 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3F65F450C6E72513995C5B87 /* CoreGraphics.framework */; };
11+
0D0EF7661D6C980F006CCCFF /* EBMute.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 0D0EF7651D6C980F006CCCFF /* EBMute.mp3 */; };
1112
0D10E0BC1D51C4D700DE58D2 /* UILabel+ContentSize.h in Headers */ = {isa = PBXBuildFile; fileRef = 0D10E0BA1D51C4D700DE58D2 /* UILabel+ContentSize.h */; };
1213
0D10E0BD1D51C4D700DE58D2 /* UILabel+ContentSize.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D10E0BB1D51C4D700DE58D2 /* UILabel+ContentSize.m */; };
1314
0D7107FA1D4B909D00EACCCE /* EBBannerView.h in Headers */ = {isa = PBXBuildFile; fileRef = 0D7107F31D4B909D00EACCCE /* EBBannerView.h */; };
@@ -23,6 +24,8 @@
2324
0D86984C1D40989000AEE574 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0D86984B1D40989000AEE574 /* Assets.xcassets */; };
2425
0D86984F1D40989000AEE574 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0D86984D1D40989000AEE574 /* LaunchScreen.storyboard */; };
2526
0DB461A01D6C888E00A4F924 /* EBBannerView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0DB4619F1D6C888E00A4F924 /* EBBannerView.xib */; };
27+
0DB461A51D6C8C1600A4F924 /* EBMuteDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = 0DB461A21D6C8C1600A4F924 /* EBMuteDetector.h */; };
28+
0DB461A61D6C8C1600A4F924 /* EBMuteDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DB461A31D6C8C1600A4F924 /* EBMuteDetector.m */; };
2629
171B5D9A0575676017E8EE61 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A0FFDCE723D5845050270ABC /* CFNetwork.framework */; };
2730
17C43ECA53E22D1ADD65C11F /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DCF6E72182B28B48D76FA8BD /* CoreFoundation.framework */; };
2831
3B3C7C166BA15C1F3089197D /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 217CFE021A532761C428C35E /* libz.tbd */; };
@@ -35,6 +38,7 @@
3538
/* End PBXBuildFile section */
3639

3740
/* Begin PBXFileReference section */
41+
0D0EF7651D6C980F006CCCFF /* EBMute.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = EBMute.mp3; sourceTree = "<group>"; };
3842
0D10E0BA1D51C4D700DE58D2 /* UILabel+ContentSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UILabel+ContentSize.h"; sourceTree = "<group>"; };
3943
0D10E0BB1D51C4D700DE58D2 /* UILabel+ContentSize.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UILabel+ContentSize.m"; sourceTree = "<group>"; };
4044
0D7107F31D4B909D00EACCCE /* EBBannerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EBBannerView.h; sourceTree = "<group>"; };
@@ -54,6 +58,8 @@
5458
0D86984E1D40989000AEE574 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
5559
0D8698501D40989000AEE574 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5660
0DB4619F1D6C888E00A4F924 /* EBBannerView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EBBannerView.xib; sourceTree = "<group>"; };
61+
0DB461A21D6C8C1600A4F924 /* EBMuteDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EBMuteDetector.h; sourceTree = "<group>"; };
62+
0DB461A31D6C8C1600A4F924 /* EBMuteDetector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EBMuteDetector.m; sourceTree = "<group>"; };
5763
217CFE021A532761C428C35E /* libz.tbd */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
5864
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; };
5965
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; };
@@ -107,6 +113,9 @@
107113
0D7107F81D4B909D00EACCCE /* UIImage+ColorAtPoint.m */,
108114
0D10E0BA1D51C4D700DE58D2 /* UILabel+ContentSize.h */,
109115
0D10E0BB1D51C4D700DE58D2 /* UILabel+ContentSize.m */,
116+
0D0EF7651D6C980F006CCCFF /* EBMute.mp3 */,
117+
0DB461A21D6C8C1600A4F924 /* EBMuteDetector.h */,
118+
0DB461A31D6C8C1600A4F924 /* EBMuteDetector.m */,
110119
);
111120
path = Classes;
112121
sourceTree = "<group>";
@@ -188,6 +197,7 @@
188197
0D7107FE1D4B909D00EACCCE /* UIImage+ColorAtPoint.h in Headers */,
189198
0D7108001D4B909D00EACCCE /* EBForeNotification.h in Headers */,
190199
0D7107FA1D4B909D00EACCCE /* EBBannerView.h in Headers */,
200+
0DB461A51D6C8C1600A4F924 /* EBMuteDetector.h in Headers */,
191201
0D10E0BC1D51C4D700DE58D2 /* UILabel+ContentSize.h in Headers */,
192202
);
193203
runOnlyForDeploymentPostprocessing = 0;
@@ -254,6 +264,7 @@
254264
buildActionMask = 2147483647;
255265
files = (
256266
0D86984F1D40989000AEE574 /* LaunchScreen.storyboard in Resources */,
267+
0D0EF7661D6C980F006CCCFF /* EBMute.mp3 in Resources */,
257268
0DB461A01D6C888E00A4F924 /* EBBannerView.xib in Resources */,
258269
0D86984C1D40989000AEE574 /* Assets.xcassets in Resources */,
259270
0D86984A1D40989000AEE574 /* Main.storyboard in Resources */,
@@ -267,6 +278,7 @@
267278
isa = PBXSourcesBuildPhase;
268279
buildActionMask = 2147483647;
269280
files = (
281+
0DB461A61D6C8C1600A4F924 /* EBMuteDetector.m in Sources */,
270282
0D8698471D40989000AEE574 /* ViewController.m in Sources */,
271283
0D7107FD1D4B909D00EACCCE /* EBForeNotification.m in Sources */,
272284
0D10E0BD1D51C4D700DE58D2 /* UILabel+ContentSize.m in Sources */,

demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification.xcodeproj/xcuserdata/wuxingchen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
version = "2.0">
55
<Breakpoints>
66
<BreakpointProxy
7-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
7+
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
88
<BreakpointContent
99
shouldBeEnabled = "Yes"
1010
ignoreCount = "0"
1111
continueAfterRunningActions = "No"
12-
filePath = "iOS-Foreground-Push-Notification/UINavigationController+EBForeNotification.m"
13-
timestampString = "491303379.258775"
14-
startingColumnNumber = "9223372036854775807"
15-
endingColumnNumber = "9223372036854775807"
16-
startingLineNumber = "28"
17-
endingLineNumber = "28">
12+
scope = "0"
13+
stopOnStyle = "0">
1814
</BreakpointContent>
1915
</BreakpointProxy>
2016
</Breakpoints>

demo/iOS-Foreground-Push-Notification/iOS-Foreground-Push-Notification/EBForeNotification/Classes/EBForeNotification.m

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,14 @@
1111
#import <UIKit/UIKit.h>
1212
#import "EBBannerView.h"
1313
#import "UIImage+ColorAtPoint.h"
14-
14+
#import "EBMuteDetector.h"
1515

1616
NSString *const EBBannerViewDidClick = @"EBBannerViewDidClick";
1717

1818
@implementation EBForeNotification
1919

2020
#pragma mark - public
2121

22-
+(void)handleRemoteNotification:(NSDictionary*)userInfo soundID:(int)soundID isIos10:(BOOL)isIos10{
23-
if (userInfo) {
24-
id aps = [userInfo valueForKey:@"aps"];
25-
if (aps && [aps isKindOfClass:[NSDictionary class]] && [aps valueForKey:@"alert"] && ![[aps valueForKey:@"alert"] isEqual: @""]) {
26-
[EBForeNotification showBannerWithUserInfo:userInfo soundID:soundID isIos10:isIos10];
27-
}
28-
}
29-
}
30-
3122
+(void)handleRemoteNotification:(NSDictionary*)userInfo soundID:(int)soundID{
3223
[EBForeNotification handleRemoteNotification:userInfo soundID:soundID isIos10:NO];
3324
}
@@ -45,11 +36,26 @@ +(void)handleRemoteNotification:(NSDictionary*)userInfo customSound:(NSString*)s
4536
}
4637
}
4738

39+
+(void)handleRemoteNotification:(NSDictionary*)userInfo soundID:(int)soundID isIos10:(BOOL)isIos10{
40+
if (userInfo) {
41+
id aps = [userInfo valueForKey:@"aps"];
42+
if (aps && [aps isKindOfClass:[NSDictionary class]] && [aps valueForKey:@"alert"] && ![[aps valueForKey:@"alert"] isEqual: @""]) {
43+
[EBForeNotification showBannerWithUserInfo:userInfo soundID:soundID isIos10:isIos10];
44+
}
45+
}
46+
}
47+
4848
#pragma mark - private
4949

5050
+(void)showBannerWithUserInfo:(NSDictionary*)userInfo soundID:(int)soundID isIos10:(BOOL)isIos10{
5151
if (soundID) {
52-
AudioServicesPlaySystemSound(soundID);
52+
[[EBMuteDetector sharedDetecotr] detectComplete:^(BOOL isMute) {
53+
if (isMute) {
54+
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
55+
}else{
56+
AudioServicesPlaySystemSound(soundID);
57+
}
58+
}];
5359
}
5460
if (SharedBannerView) {
5561
SharedBannerView = nil;

0 commit comments

Comments
 (0)