标签: uilocalnotification

在本地通知中播放声音

我在我的应用程序中使用了本地通知,并在正确的时间成功生成了警报.

但是,当我尝试使用代码播放声音时,它无法播放....

localNot.soundName = @"Ghulam Ali-Chamkte Chaad Ko.mp3";

任何人都可以告诉我原因....声音文件的播放长度是否会影响

iphone uilocalnotification

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

如何跟踪当前安排的UILocalNotifications

MyObject : NSObject
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSArray *notificationsArray;
Run Code Online (Sandbox Code Playgroud)

我在tableView中有一个MyObjects数组,可以根据名称,通知时间等进行编辑.目前,我进行了设置,所以当用户按下Save时,当前的MyObject会保存到我的DataManager的myObjectArray中.

DataManager : NSObject
@property (nonatomic, strong) NSMutableArray *myObjectArray;
Run Code Online (Sandbox Code Playgroud)

我在DataManager中调用我的方法来遍历该MyObject实例,以安排该MyObject的通知.

我认为这没问题,直到用户点击其中一个MyObjects来编辑时间,然后我才需要重新安排该对象的通知.我知道你可以得到

[[UIApplication sharedApplication] scheduledNotifications];
Run Code Online (Sandbox Code Playgroud)

但是由此,我不知道哪个通知针对哪个对象.因此,在这种情况下,最好取消整个应用程序的所有通知,然后在DataManager中为每个MyObject实例循环遍历myObjectArray,并为每个对象安排通知吗?

谢谢!

iphone uilocalnotification

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

后台任务即将到期时的本地通知

iOS应用程序可以在后台任务即将到期时安排本地通知吗?当应用程序使用NSOperationQueue进入后台时,基本上我有一些服务器端正在进行下载.
我想要的是当后台任务即将完成时通过本地通知通知用户.那么该用户可以将应用程序带到前台以保持持续的服务器数据下载
以下是我正在使用的代码,但我没有看到任何本地通知

UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler: ^{
        dispatch_async(dispatch_get_main_queue(), ^{
           /*TO DO
            prompt the user if they want to continue syncing through push notifications. This will get the user to essentially wake the app so that sync can continue.
             */
            // create the notification and then set it's parameters
            UILocalNotification *beginNotification = [[[UILocalNotification alloc] init] autorelease];
            if (beginNotification) {
                beginNotification.fireDate = [NSDate date];
                beginNotification.timeZone = [NSTimeZone defaultTimeZone];
                beginNotification.repeatInterval = 0;
                beginNotification.alertBody = @"App is about to exit .Please bring …
Run Code Online (Sandbox Code Playgroud)

background ios uilocalnotification

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

本地通知"每天上午7:00"没有通知

我希望每天早上7点发出通知,但不会发生.我也想让它在锁屏中显示.这是我到目前为止的所有代码.

-(void)EveryDayNotify

{

    NSLog(@"Good Morning Working");

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];


    [localNotification setAlertBody:@"Good Morning! Have a great day!"];
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.applicationIconBadgeNumber = 1;

    localNotification.repeatInterval = NSDayCalendarUnit;

    NSCalendar *calendar = [NSCalendar currentCalendar]; // gets default calendar
    NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]]; // gets the year, month, day,hour and minutesfor today's date
    [components setHour:07];
    [components setMinute:0];

    localNotification.fireDate = [calendar dateFromComponents:components];


    [localNotification release];
}
Run Code Online (Sandbox Code Playgroud)

iphone xcode ipad ios uilocalnotification

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

如何让我的计时器在后台运行,然后发送本地通知?

由于某种原因,我的计时器只在前台运行.我在这里寻找解决方案,但我找不到任何好的解决方案.我的计时器使用Core Data,每次减量后都会保存timeInterval.此外,我发送UILocalNotification,但这不起作用.我假设它不发送警报视图,如果它在前台..这就是我现在拥有的:

-(IBAction)startTimer:(id)sender{
    if (timer == nil) {
        [startButton setTitle:@"Pause" forState:UIControlStateNormal];
       timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
    } else {
        [startButton setTitle:@"Resume" forState:UIControlStateNormal];
        [timer invalidate];
        timer = nil;
    }

}
-(void)timerAction:(NSTimer *)t
{
    if(testTask.timeInterval == 0)
    {
        if (self.timer)
        {
            [self timerExpired];
            [self.timer invalidate];
            self.timer = nil;
        }
    }
    else
    {
        testTask.timeInterval--;
        NSError *error;
        if (![self.context save:&error]) {
            NSLog(@"couldn't save: %@", [error localizedDescription]);
        }
    }
    NSUInteger seconds = (NSUInteger)round(testTask.timeInterval);
    NSString *string = [NSString stringWithFormat:@"%02u:%02u:%02u",
                        seconds / 3600, (seconds …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nstimer ios uilocalnotification

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

本地通知声音没有播放?

我对本地通知有这个问题,他们没有播放声音.我测试了默认的一个和自定义的那个显然是我想玩但没有!我看了很多人都面临这个问题,但他们的解决方案都没有对我有用.

UILocalNotification *local

- (IBAction)Dateaction:(id)sender {

    local = [[UILocalNotification alloc]init];
    local.timeZone = [NSTimeZone defaultTimeZone];
    local.alertBody = [NSString stringWithFormat:@"%@ Recuerda que tienes que: %@", [[NSUserDefaults standardUserDefaults] objectForKey:@"user"], [[NSUserDefaults standardUserDefaults] objectForKey:@"selected"]];
    local.fireDate = [self.DatePicker date];
   /* if ([[self.userdefaults objectForKey:@"sound"]isEqualToString:@"sound1"]) {
        local.soundName = @"sound1.caf";
    }else if([[self.userdefaults objectForKey:@"sound"]isEqualToString:@"sound2"]){
        local.soundName = @"sound2.caf";
    }else if([[self.userdefaults objectForKey:@"sound"]isEqualToString:@"sound1"]){
        local.soundName = @"sound3.caf";
    }else{
        local.soundName = @"sound1.caf";
    }*/
    local.soundName = UILocalNotificationDefaultSoundName;


}

- (IBAction)switchChanged:(id)sender {
if(self.NotSwith.isOn == YES){
        [[UIApplication sharedApplication] scheduleLocalNotification:local];


       }
}
Run Code Online (Sandbox Code Playgroud)

audio objective-c ios uilocalnotification

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

如何以编程方式触发UILocalNotification?

UILocalNotification有一个.fireDate方法,NSDate作为一个参数然后在那时触发.但是,如果我想在我的代码中发生某些事情而不使用它的话,我该NSDate怎么办?

ios uilocalnotification swift

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

尝试创建本地通知但在swift 2中收到错误"无法调用非函数类型uilocalnotification的值"

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()


        var dateComp:NSDateComponents = NSDateComponents()
        dateComp.year = 2015;
        dateComp.month = 11;
        dateComp.day = 20;
        dateComp.hour = 0;
        dateComp.minute = 10;
        dateComp.timeZone = NSTimeZone.systemTimeZone()

        var calendar:NSCalendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)!
        var date:NSDate = calendar.dateFromComponents(dateComp)!
        //var date:NSDate = calendar.dateFromComponents(dateComp)

        var notification:UILocalNotification = UILocalNotification()
        notification.category = "FIRST_CATEGORY"
        notification.alertBody = "HI, noti "
        notification.fireDate  = date

        UIApplication.sharedApplication().scheduledLocalNotifications(notification)


        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() { …
Run Code Online (Sandbox Code Playgroud)

xcode ios uilocalnotification swift swift2

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

操作按钮未显示在本地通知ios 9.2 swift 2中

我在循环中创建通知,相关代码是:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    appDelegate = self

    serNotificationType = UIUserNotificationType.Alert.union(UIUserNotificationType.Sound).union(UIUserNotificationType.Badge)

    let completeAction = UIMutableUserNotificationAction()
    completeAction.identifier = "COMPLETE" // the unique identifier for this action
    completeAction.title = "Clear" // title for the action button
    completeAction.activationMode = .Background // UIUserNotificationActivationMode.Background - don't bring app to foreground
    completeAction.authenticationRequired = false // don't require unlocking before performing action
    completeAction.destructive = true // display action in red

    let callInAction = UIMutableUserNotificationAction()
    callInAction.identifier = "CALLIN"
    callInAction.title = "Call now" …
Run Code Online (Sandbox Code Playgroud)

ios uilocalnotification swift2

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

iOS 9中的UILocalNotification和iOS 10中的UNMutableNotificationContent?

我需要向项目提供向后兼容性(iOS 9).我想出了这个:

if #available(iOS 10.0, *) {
        let content = UNMutableNotificationContent()
    } else {
        // Fallback on earlier versions
    }
Run Code Online (Sandbox Code Playgroud)

我应该在Fallback中写些什么?我是否需要创建本地通知实例?

iphone uilocalnotification ios9 swift3 ios10

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