标签: uilocalnotification

UILocalNotification自定义声音不在iOS7中播放

我正在UILocalNotification申请中使用.

在应用程序中有两种声音有条件地播放 - 我已经为它们应用了适当的条件.

但是当我安装应用程序并在iOS 7设备上运行它时,它会触发本地通知,但声音不会在应用程序中播放.

下面给出了代码来设置通知:

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    if (localNotification == nil)
        return;
    localNotification.fireDate = [pickerView date];

    localNotification.timeZone = [NSTimeZone defaultTimeZone];

    if (alarm_number == 1) {
        localNotification.alertBody = [NSString stringWithFormat:@"First Alarm"];
    }
    else
    {
        localNotification.alertBody = [NSString stringWithFormat:@"Second Alarm"];
    }

    localNotification.alertAction =@"Ok";

    NSString *message = [[NSString alloc]initWithString:@""];

    if(alarm_number == 1)
    {
        localNotification.soundName=@"Alarm_1.mp3";
        message = @"First Alarm Scheduled";
    }
    else
    {
        localNotification.soundName=@"Alarm_2.mp3";
        message = @"Second Alarm Scheduled";
    }

    localNotification.applicationIconBadgeNumber = 1;

    // …
Run Code Online (Sandbox Code Playgroud)

iphone audio ios uilocalnotification ios7

16
推荐指数
2
解决办法
1万
查看次数

如何在iOS中收听通知被驳回的事件?

我正在列出为我的本地通知按下的操作,但有没有办法确定用户何时解除通知?

这是我在AppDelegate中听我的动作的方式,但是解雇并没有解雇这个问题:

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler: () -> Void) {
        var actionName: String? = nil

        if let identifier = identifier {
            switch identifier {
                case "snoozeAction":
                    actionName = "snoozeActionTapped"
                    break
                default: break
            }

            if let name = actionName {
                NSNotificationCenter.defaultCenter().postNotificationName(name, object: nil)
            }
        }

        completionHandler()
    }
Run Code Online (Sandbox Code Playgroud)

apple-push-notifications ios uilocalnotification ios8

15
推荐指数
1
解决办法
2223
查看次数

对Swift 2中registerUserNotificationSettings的更改?

我似乎找不到有关registerUserNotificationSettings的任何文档,超出了去年11月(这里)生成的文件,但我的旧代码似乎在Xcode 7和Swift 2中不再适用于我.

我在App Delegate中有这个代码:

let endGameAction = UIMutableUserNotificationAction()
endGameAction.identifier = "END_GAME"
endGameAction.title = "End Game"
endGameAction.activationMode = .Background
endGameAction.authenticationRequired = false
endGameAction.destructive = true

let continueGameAction = UIMutableUserNotificationAction()
continueGameAction.identifier = "CONTINUE_GAME"
continueGameAction.title = "Continue"
continueGameAction.activationMode = .Foreground
continueGameAction.authenticationRequired = false
continueGameAction.destructive = false

let restartGameCategory = UIMutableUserNotificationCategory()
restartGameCategory.identifier = "RESTART_CATEGORY"
restartGameCategory.setActions([continueGameAction, endGameAction], forContext: .Default)
restartGameCategory.setActions([endGameAction, continueGameAction], forContext: .Minimal)

application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: (NSSet(array: [restartGameCategory])) as Set<NSObject>))
Run Code Online (Sandbox Code Playgroud)

我现在在最后一行代码中收到以下两个错误:

'Element.Protocol'没有名为'Alert'的成员

无法使用类型为'(UIUserNotificationSettings)'的参数列表调用'registerUserNotificationSettings'

我搜索了有关任何变化的信息,但我找不到任何东西.我错过了一些明显的东西吗

uilocalnotification swift swift2

15
推荐指数
2
解决办法
8878
查看次数

检测应用程序打开的UILocalNotification

在某些情况下,我的iOS应用程序触发多个UILocalNotification同一时间.我想决定UILocalNotification用户点击了哪个.当用户点击某个UILocalNotification应用程序处于非活动状态或后台时.问题是该方法

func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
Run Code Online (Sandbox Code Playgroud)

每次触发都会UILocalNotification被调用.因此,当应用程序变为活动状态时,此方法会被多次调用,因为我收到了多个UILocalNotification.有没有办法确定UILocalNotification应用程序打开的原因是什么?由于UILocalNotification应用程序处于非活动状态或后台时已收到所有应用程序,因此检查applicationState 不起作用.

非常感谢!

编辑:作为一个例子:当您从两个不同的组A和B收到WhatsApp消息并从组A中选择推送通知时,该应用程序将在应用程序打开后立即显示.WhatsApp和我的用例之间的区别在于我有本地通知.

notifications ios uilocalnotification swift

15
推荐指数
2
解决办法
1714
查看次数

使用swift在设定的时间每天重复本地通知

我是iOS开发的新手,但已经创建了应用程序,我正在尝试创建一段时间的每日通知.目前,通知对于给定的日期/时间执行一次.我不确定如何使用repeatInterval方法每天安排它.每天重复通知的最佳方法是什么?任何帮助将不胜感激(Y).

    var dateComp:NSDateComponents = NSDateComponents()
    dateComp.year = 2015;
    dateComp.month = 06;
    dateComp.day = 03;
    dateComp.hour = 12;
    dateComp.minute = 55;
    dateComp.timeZone = NSTimeZone.systemTimeZone()

    var calender:NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
    var date:NSDate = calender.dateFromComponents(dateComp)!

    var notification:UILocalNotification = UILocalNotification()
    notification.category = "Daily Quote"
    notification.alertBody = quoteBook.randomQuote()
    notification.fireDate = date
    notification.repeatInterval = 

    UIApplication.sharedApplication().scheduleLocalNotification(notification)
Run Code Online (Sandbox Code Playgroud)

cocoa-touch ios uilocalnotification swift

14
推荐指数
2
解决办法
2万
查看次数

基于动态位置的本地通知Swift iOS

当用户接近停止时,我试图获取总线的到达时间,我已经测试通过发送基本的本地通知来确保区域被正确触发,我还测试了我的Web服务调用以确保它正常工作.

但是我很难获取信息,然后发送通知.

这是我的代码:

    var bgTask: UIBackgroundTaskIdentifier = UIBackgroundTaskIdentifier()

    bgTask = UIApplication.shared().beginBackgroundTask {

        self.webService?.getStopEstimates(routeStopIds: stopRouteIdSet, routeNameDict: routeNameDict, completion: { (result) in

            if result == "error" {
                return
            }

            let notification = UILocalNotification()
            notification.fireDate = Date(timeIntervalSinceNow: 1)
            notification.alertTitle = region.identifier + " Stop Details"
            notification.alertBody = result
            notification.soundName = UILocalNotificationDefaultSoundName
            UIApplication.shared().scheduleLocalNotification(notification)
        })

        UIApplication.shared().endBackgroundTask(bgTask)
    }
Run Code Online (Sandbox Code Playgroud)

任何人都明白为什么它可能不会发送?我启用了后台提取和位置服务.这是在里面didEnterRegion

core-location ios uilocalnotification swift

14
推荐指数
2
解决办法
1186
查看次数

当应用程序在后台并且手机处于振动状态时,Alarmy等警报应用程序如何能够在iPhone上播放声音

我正在研究可以提醒用户注意某些重要事情的应用程序.我使用本地通知来提醒用户.在iOS上,我发现如果手机处于振动状态,通知将不会响铃.对于应用程序的许多用户来说,这是一个交易破坏者,但我一直把这个问题放到现在,因为我认为如果应用程序在后台,iOS不允许应用播放声音.

即使手机处于振动状态,音乐应用也可以通过启用音频背景模式播放歌曲,但不允许您安排在特定时间播放歌曲.

最近我看到一些应用程序能够在特定时间播放声音,即使该应用程序在后台.一个这样的应用程序是Alarmy警报应用程序.当警报到期时,我不认为他们正在通过本地通知播放音乐,因为即使在我清除通知后音乐仍继续播放.从本地通知文档中,我了解到在本地通知触发之前我无法运行任何代码,直到用户点击通知为止.所以,我无法启动一个可以在振动中播放声音的音频播放器.

即使手机处于振动状态并且应用程序在iOS中处于后台,这些应用程序如何才能播放声音?

iphone ios uilocalnotification

14
推荐指数
2
解决办法
1971
查看次数

本地通知"didReceiveLocalNotification"调用两次

我使用以下方式处理本地通知:

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
Run Code Online (Sandbox Code Playgroud)

并安排本地通知:

- (void)scheduleNotificationWithInterval:(int)minutesBefore {
    UILocalNotification *localNotif = [[UILocalNotification alloc] init];

    if (localNotif == nil)
        return;

    NSDate *fireDate = [NSDate date];
    localNotif.fireDate = [fireDate dateByAddingTimeInterval:minutesBefore*60];
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    localNotif.repeatInterval = kCFCalendarUnitMinute;
    localNotif.alertBody = [NSString stringWithFormat:NSLocalizedString(@"LocalEvent notification in %i minutes.", nil),minutesBefore];
    localNotif.alertAction = NSLocalizedString(@"View Details", nil);
    localNotif.applicationIconBadgeNumber = 1;

    NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"This is dict, you can pass info for your notification",@"info",nil];
    localNotif.userInfo = infoDict;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

    [localNotif release];
    NSLog(@"Event scheduled");
}
Run Code Online (Sandbox Code Playgroud)

当我收到通知时, …

iphone notifications ios uilocalnotification

13
推荐指数
2
解决办法
1万
查看次数

申请终止的本地通知

我正在开发一个应用程序,如果终止它将无法工作.它有一些后台任务.如果应用程序被终止,我想显示本地通知.有些应用程序执行此操作意味着这是可行的.但我无法找到方法.

我试图在applicationWillTerminate:appdelegate的方法中设置本地通知,并在我的viewcontroller中添加了应用终止的通知,但是当app实际终止时,没有任何方法被调用.

- (void)applicationWillTerminate:(UIApplication *)application
{
    NSLog(@"terminated");
    UIApplication * app = [UIApplication sharedApplication];
    NSDate *date = [[NSDate date] dateByAddingTimeInterval:15];
    UILocalNotification *alarm = [[UILocalNotification alloc] init] ;
    if (alarm) {
        alarm.fireDate = [NSDate date];
        alarm.timeZone = [NSTimeZone defaultTimeZone];
        alarm.repeatInterval = 0;
        alarm.alertBody = @"This app does not work if terminated";
        alarm.alertAction = @"Open";
        [app scheduleLocalNotification:alarm];
    }

    [app presentLocalNotificationNow:alarm];
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
Run Code Online (Sandbox Code Playgroud)

任何帮助都会很棒.

提前致谢 !!!

iphone uiapplicationdelegate uilocalnotification

13
推荐指数
3
解决办法
1万
查看次数

iOS 7默认情况下没有声音的本地通知

当我在iOS 7设备上运行应用程序时,该应用程序不会出现在设备通知设置中,并且在发出通知时不会发出声音.只有在第一次通知被触发后,我才会在关闭声音的通知设置列表下看到我的应用.

  1. 为什么应用程序最初不会显示在通知列表中?

  2. 为什么声音默认关闭?

在iOS 5和6上,我没有这些问题.这些是本地通知.

xcode objective-c ios uilocalnotification ios7

13
推荐指数
1
解决办法
3018
查看次数