我已经在我的iPad应用中使用了UINotification
。我正在尝试将声音添加到我的通知消息中。我尝试了默认和自定义的一个,我已经添加到我的捆绑包中,但两个都无法正常工作。
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = nil;
localNotification.alertBody = @"Message";
localNotification.soundName = @"ALERT.mp3"; // UILocalNotificationDefaultSoundName
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
两者都不起作用,我听不到任何声音。
答案 0 :(得分:0)
试试这个 并检查您的声音文件是否不应大于30 秒。 在你的app delegate中写下这个
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
- (void)scheduleNotification {
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil) {
UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = insert your date;
notif.timeZone = [NSTimeZone localTimeZone];
notif.alertBody = your message body;
notif.repeatInterval = 0;
notif.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
}
}