我已经在我的iPhon App中完成了我的UILoocalNotification。我正在尝试将声音添加到我的通知消息中。我尝试了默认和自定义的一个,我已经添加到我的捆绑包中,但两个都无法正常工作。
我正在使用xcode 6.1.1
这是我的代码
-(void)localNotificaiton{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
//localNotif.fireDate = date; // date after 10 sec from now
localNotif.timeZone = [NSTimeZone defaultTimeZone];
// Notification details
localNotif.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
localNotif.alertBody = [[self.allMsgsArray objectAtIndex:0]objectForKey:@"name"]; // text of you that you have fetched
// Set the action button
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
//// localNotif.soundName = [[NSBundle mainBundle] pathForResource:@“Bell”ofType:@“wav”];
// Specify custom data for the notification
//NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
NSMutableDictionary *infoDict = [[NSMutableDictionary alloc]init];
[infoDict setObject: [[self.allMsgsArray objectAtIndex:0]objectForKey:@"name"] forKey:@"name"];
localNotif.userInfo = infoDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
// Handle the notificaton when the app is running
UIApplicationState state = [app applicationState];
if (state == UIApplicationStateActive) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notification"
message:[NSString stringWithFormat:@"New Message: %@" ,notif.alertBody]
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
// Set icon badge number to zero
app.applicationIconBadgeNumber = 0;
}
我听不到任何声音。电话音量已满。
我的应用收到了所有通知。一旦它运行,当用户改变一些其他结束我的应用程序得到通知,都弹出并添加到通知中心...但没有声音请指导我在哪里我做错了:(