ios - 预先通知

标签 ios notificationcenter

是否可以将应用设置为在指定时间从自身发送通知?也许将他们排在队列中?到目前为止,我必须经过一个推送通知服务器,当我在每个星期二早上发送消息时,这似乎已被淘汰。另外,这叫什么(以便我可以更好地在网络上进行研究)

最佳答案

您可以像这样安排通知:

- (void)scheduleNotification
{
    //Cancel all previous Local Notifications
    [[UIApplication sharedApplication] cancelAllLocalNotifications];

    //Set new Local Notifications
    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil)
    {
        UILocalNotification *notif = [[cls alloc] init];
        //3 days
        notif.fireDate = [NSDate dateWithTimeInterval:60.0f*60.0f*24.0f*3.0f sinceDate:[NSDate date]];
        notif.timeZone = [NSTimeZone defaultTimeZone];
        notif.alertBody = @"Come Back Again! Lets blast All Zombie!";
        notif.alertAction = @"PLAY";
        notif.soundName = UILocalNotificationDefaultSoundName;
        notif.applicationIconBadgeNumber = 1;
        [[UIApplication sharedApplication] scheduleLocalNotification:notif];
        }    
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [application registerForRemoteNotificationTypes:
     UIRemoteNotificationTypeBadge |
     UIRemoteNotificationTypeAlert |
     UIRemoteNotificationTypeSound];

    [self scheduleNotification];
    ..
}

关于ios - 预先通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17789180/

相关文章:

iphone - "Distribution"和 "Release"构建配置有什么区别?

iphone - 如何通过在 iOS 中显示正数的 + 号将 int 格式化为 NSString

ios - 如何在iOS8模拟器中测试方向锁定?

macos - 复制像《Mountain Lion》中的通知中心一样向一侧滑动的屏幕?

ios - 如何在NotificationCenter中使用Struct作为Observer

ios - UItableview 行与文本字段重叠

objective-c - RKObjectLoader使用数组参数截断我的路径

ios - 类型 'UIApplication' 没有成员 'didBecomeActiveNotification'

swiftui - 带有NotificationCenter发布者的SwiftUI

ios - 如何从包含的应用程序更新我的 iOS Today 小部件?