【问题标题】:Alarm Local Notification at IOS 7 Locked screen Objective-CIOS 7锁定屏幕Objective-C的警报本地通知
【发布时间】:2016-01-28 12:19:36
【问题描述】:

我正在练习在 IOS 7 上开发警报应用程序,例如警报。 Alarm time up on IOS7 但是,我在锁定屏幕时停留在本地通知,就像这样。 My notification 我做的一些代码:

在我的 AppDelegate.m 中

我的代码

[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];

    // Handle launching from a notification
    UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];

....
..in my ViewController.m..

[self scheduleLocalNotificationWithDate:correctDate];
....
(void)scheduleLocalNotificationWithDate:(NSDate *)fireDate {

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

    localNotification.fireDate = fireDate;
    localNotification.alertBody = [NSString stringWithFormat:@"Alert Fired at %@", fireDate];
    localNotification.soundName = UILocalNotificationDefaultSoundName;

    localNotification.applicationIconBadgeNumber = numberReminder;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

谁能帮忙?

谢谢

【问题讨论】:

    标签: objective-c localnotification


    【解决方案1】:

    第三方应用程序不会像系统闹钟应用程序那样出现在锁定屏幕上 - 您的应用程序只能生成普通通知。如果您想添加一个 API 来获得全屏警报样式,您可以尝试filing an enhancement request

    【讨论】:

    • 你能详细解释一下 API 吗?
    【解决方案2】:
     if([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
    }
    
    UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    
    if(notification) {       
        application.applicationIconBadgeNumber = 0;
    }
    

    并在 View Controller.m 中调用这个函数

    - (void) Notify {
    NSDate *fireDate = [[NSDate alloc]init];
    fireDate = self.datePicker.date;    
    
    NSCalendar *cal = [NSCalendar currentCalendar];
    NSDateComponents *dateComp = [cal components:(NSCalendarUnitHour | NSCalendarUnitMinute| NSCalendarUnitSecond) fromDate:fireDate];    
    
    NSDate *dd = [cal dateByAddingComponents:dateComp toDate:fireDate options:0];    
    
    UILocalNotification *notification = [[UILocalNotification alloc]init];
    [notification setFireDate:dd]; 
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
    

    }

    【讨论】:

    • 这……只是尝试做 OP 的代码已经做的事情,只是它甚至不起作用,因为您在创建它后没有使用通知调用 +scheduleLocalNotification:
    • 抱歉代码不完整,已经编辑。希望这行得通。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    相关资源
    最近更新 更多