【发布时间】:2015-06-11 06:54:19
【问题描述】:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"MessageReceived" object:self];
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive)
{
// NSString *cancelTitle = @"Close";
NSString *showTitle = @"Show";
// NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"New Order"
message:@"You just received new order"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:showTitle, nil];
UILocalNotification *localNotifcation = [[UILocalNotification alloc] init];
localNotifcation.userInfo = userInfo;
localNotifcation.soundName = UILocalNotificationDefaultSoundName;
// localNotifcation.alertBody = message;
localNotifcation.fireDate = [NSDate date];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotifcation];
[alertView show];
}
else {
//Do stuff that you would do if the application was not active
}
}
请给我一个解决方案,如果现在使用 x-code 6.3 收到通知,我如何在应用程序运行时发出声音?
【问题讨论】:
-
您可以使用带有自定义铃声的 AVAudioPlayer 来播放。
标签: ios objective-c iphone