-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDefaultPushHandle.m
More file actions
85 lines (70 loc) · 2.42 KB
/
DefaultPushHandle.m
File metadata and controls
85 lines (70 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#import "DefaultPushHandle.h"
#import <AVFoundation/AVFoundation.h>
@implementation DefaultPushHandle
{
AVAudioPlayer *_audioPlayer;;
}
/**
* 修饰PushHandle, 添加新的功能
*
* @param userInfo APNS服务器返回数据信息
*/
- (void)handleUserInfo:(NSDictionary *)userInfo
{
NSLog(@"默认_SDK操作 UserInfo: %@", userInfo);
[super handleUserInfo:userInfo];
NSString *param;
if ( [[userInfo objectForKey:@"aps"] objectForKey:@"alert"] ) {
param = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
[self handleDefaultAlert:param];
}
if ( [[userInfo objectForKey:@"aps"] objectForKey:@"sound"] ) {
param = [[userInfo objectForKey:@"aps"] objectForKey:@"sound"];
[self handleDefaultSound:param];
}
if ( [[userInfo objectForKey:@"aps"] objectForKey:@"badge"] ) {
param = [[userInfo objectForKey:@"aps"] objectForKey:@"badge"];
[self handleDefaultBadge:param];
}
}
#pragma mark -
#pragma mark - 默认处理APNS基础参数
/**
* 默认弹出警告框, alert为Message内容
*/
- (void)handleDefaultAlert:(NSString *)alert
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
message:alert
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil, nil];
[alertView show];
}
/**
* 默认播放铃声, sound文件名称, 例如: sound.caf
*/
- (void)handleDefaultSound:(NSString *)sound
{
if (_audioPlayer != nil) {
[_audioPlayer stop];
_audioPlayer = nil;
}
NSString *musicPath = [[NSBundle mainBundle] pathForResource:[sound stringByDeletingPathExtension] ofType:[sound pathExtension]];
// 如果找不到音频文件, 则跳过播放音频
if (!musicPath) {
return;
}
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[sound stringByDeletingPathExtension] ofType:[sound pathExtension]]];
_audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[_audioPlayer prepareToPlay];
[_audioPlayer play];
}
/**
* 默认修改小红点数值
*/
- (void)handleDefaultBadge:(NSString *)badge
{
[UIApplication sharedApplication].applicationIconBadgeNumber = badge.integerValue;
}
@end