【问题标题】:iOS Can i play sound using local notification when app is in foreground [closed]iOS我可以在应用程序处于前台时使用本地通知播放声音[关闭]
【发布时间】:2013-04-16 06:36:17
【问题描述】:

当应用程序在前台时,本地通知声音不播放:我使用了以下代码

UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = [datePicker date];         
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = @"Did you forget something?";
notif.alertAction = @"Show me";
notif.soundName = @"step.mp3";//UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;

NSDictionary *userDict = [NSDictionary dictionaryWithObject:reminderText.text
                                                                 forKey:kRemindMeNotificationDataKey];
notif.userInfo = userDict;

[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];

【问题讨论】:

标签: iphone ios5 ios6


【解决方案1】:
UILocalNotification *localNotification = [[UILocalNotification alloc]init];

   // Set the notification time.
    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];

   // You can specify the alarm sound here.
   localNotification.soundName = UILocalNotificationDefaultSoundName;
   //OR
   localNotification.soundName = @"sound.caf";

   // Set the alertbody of the notification here.
    localNotification.alertBody = @"Test Alert";

   // Create the buttons on the notification alertview.
    localNotification.alertAction = @"View";

   // You can also specify custom dictionary to store informations
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"alarm#2" forKey:@"notifiKey"];
    localNotification.userInfo = infoDict;

    //Repeat the notification.
    localNotification.repeatInterval = NSDayCalendarUnit;

// Schedule the notification
[[UIApplication sharedApplication]scheduleLocalNotification:localNotification];

【讨论】:

    猜你喜欢
    • 2017-05-24
    • 2021-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-28
    • 1970-01-01
    • 1970-01-01
    • 2013-04-20
    相关资源
    最近更新 更多