ich*_*urs 2 objective-c apple-push-notifications ios
我一直在尝试为 iOS 上的通知实现自定义声音。
根据此处示例 3 中的 Apple 文档。我们需要做的就是确保推送通知负载应该是这样的:
{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9,
"sound" : "bingbong.aiff"
}
}
Run Code Online (Sandbox Code Playgroud)
并且 bingbong.aiff 必须放在应用程序包中。
此外,如果应用程序处于活动状态,我被建议添加以下代码:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if (application.applicationState == UIApplicationStateActive)
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"bingbong" ofType:@"aiff"];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path]error:NULL];
theAudio.delegate = self;
[theAudio play];
}
}
Run Code Online (Sandbox Code Playgroud)
"bingbong.aiff" 被放置在 "SupportingFiles"
我仍然没有获得远程通知的自定义声音。
我已经完成了与此类似的其他 SO 问题,但这些问题与我正在做的没有什么不同。
删除里面的AVPlayer东西didReceiveRemoteNotification。
确保:
您注册了推送通知:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().registerForRemoteNotifications()
return true
}
Run Code Online (Sandbox Code Playgroud)该名称与文件名完全匹配:
{
"aps" : {
"alert" : "message",
"badge" : 1,
"sound" : "name.aiff"
}
}
Run Code Online (Sandbox Code Playgroud)对于默认声音:
根据要播放默认声音的苹果文档和指南,您必须在声音文件中发送“默认”值。否则它也不会播放默认声音。
对于自定义声音:
您需要传递自定义声音文件名来代替default您的php script**.
Xcode项目资源中。UILocalNotificationDefaultSoundName
在.plist文件中添加以下键。见下图:| 归档时间: |
|
| 查看次数: |
4188 次 |
| 最近记录: |