首页 技术 正文
技术 2022年11月10日
0 收藏 611 点赞 3,022 浏览 2549 个字

主要方法:

//自定义推送
- (void)networkDidReceiveMessage:(NSNotification *)notification {
NSDictionary * userInfo = [notification userInfo];//
NSString *contentUser = [userInfo valueForKey:@"content"];//content:获取推送的内容
NSDictionary *extras = [userInfo valueForKey:@"extras"];//extras:获取用户自定义参数
NSString *customizeField1 = [extras valueForKey:@"customizeField1"]; //服务端传递的Extras附加字段,key是自己定义的 customizeField1:根据自定义key获取自定义的value
NSLog(@"接收到自定义通知 content = %@,extras = %@,customizeField1 = %@",contentUser,extras,customizeField1);
//极光自定义通知
JPushNotificationContent *content = [[JPushNotificationContent alloc] init];
//content.title = @"Test Notifications";
//content.subtitle = @"2016";
content.body = contentUser;
content.badge = @;
content.categoryIdentifier = @"Custom DAKQQSB DingDan";
content.sound = @"test.caf";
// 5s后提醒 iOS 10 以上支持
JPushNotificationTrigger *trigger1 = [[JPushNotificationTrigger alloc] init];
if(IOS10_OrLater)
{
trigger1.timeInterval = 0.001;
}
else
{
//5s后提醒,iOS10以下支持
trigger1.fireDate = [NSDate dateWithTimeIntervalSinceNow:];
} JPushNotificationRequest *request = [[JPushNotificationRequest alloc] init];
request.requestIdentifier = content.categoryIdentifier;
request.content = content;
request.trigger = trigger1;
request.completionHandler = ^(id result) {
NSLog(@"极光推送结果返回:%@", result);
};
[JPUSHService addNotification:request];
if([self runningInForeground])
{
NSLog(@"推送前台 推送前台");
}
}

但是要注意的是,自定义通知时,只有程序在后台运行才有提示音,程序在前台运行时只有提示,没有声音,所以需要在前台自己设置播放声音.不知道还有没有其他解决办法

//判断前台
-(BOOL) runningInForeground
{
UIApplicationState state = [UIApplication sharedApplication].applicationState;
BOOL result = (state == UIApplicationStateActive); return result;
}
//播放音乐
-(void)playSound{
SystemSoundID soundID;
//NSBundle来返回音频文件路径
NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"caf"];
//建立SystemSoundID对象,但是这里要传地址(加&符号)。 第一个参数需要一个CFURLRef类型的url参数,要新建一个NSString来做桥接转换(bridge),而这个NSString的值,就是上面的音频文件路径
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:soundFile], &soundID);
//播放提示音 带震动
AudioServicesPlayAlertSound(soundID);
//播放系统声音
// AudioServicesPlaySystemSound(soundID);
}
-----------错误记录

<!–
p.p1 {margin: 0.0px 0.0px 0.0px 12.0px; text-indent: -12.0px; font: 11.0px Menlo}
–>
<!–
p.p1 {margin: 0.0px 0.0px 0.0px 12.0px; text-indent: -12.0px; font: 11.0px Menlo}
–>

Undefined symbols for architecture i386:

“_OBJC_CLASS_$_JPUSHRegisterEntity”, referenced from:

objc-class-ref in AppDelegate.o

“_OBJC_CLASS_$_JPUSHService”, referenced from:

objc-class-ref in LoginViewController.o

objc-class-ref in AppDelegate.o

ld: symbol(s) not found for architecture i386

clang: error: linker command failed with exit code 1 (use -v to see invocation)

原因查了很多地方,后来才发现只是因为打包时把product-schemes-run的环境改成release了,改回debug就没这个错误了.

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,965
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781