星空网 > 软件开发 > 操作系统

iOS闹钟实现

UILocalNotification *notification=[[UILocalNotification alloc] init];
        if (notification!=nil)
        {
           
            NSDate *now=[NSDate new];
          
            //notification.fireDate=[now addTimeInterval:period];
            notification.fireDate = [now dateByAddingTimeInterval:period];
            NSLog(@"%d",period);
            notification.timeZone=[NSTimeZone defaultTimeZone];
            notification.soundName = @"ping.caf";
            //notification.alertBody=@"TIME!";
           
            notification.alertBody = [NSString stringWithFormat:@"@%时间到了!",nameStr];
           
            NSDictionary* info = [NSDictionary dictionaryWithObject:uniqueCodeStr forKey:CODE];
            notification.userInfo = info;
           
            [[UIApplication sharedApplication] scheduleLocalNotification:notification];     
           
        }

设置的时间到了以后,会自动在桌面弹出一个提示框,点显示后,就可以启动软件。然后在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (localNotif)
    {
        NSLog(@"Recieved Notification %@",localNotif);
        NSDictionary* infoDic = localNotif.userInfo;
        NSLog(@"userInfo description=%@",[infoDic description]);
        NSString* codeStr = [infoDic objectForKey:CODE];
    }
}里,对lanchOptions进行处理,找到它里面的信息,就可以拿到设置时的需要处理的东西,就可以继续操作了。

如果此时你的客户端 软件仍在打开,则会调用
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
{

}
一样的处理方法。




原标题:iOS闹钟实现

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

对外贸易经营权:https://www.goluckyvip.com/tag/30790.html
对外贸易网:https://www.goluckyvip.com/tag/30794.html
对外贸易网站:https://www.goluckyvip.com/tag/30795.html
对外贸易政策:https://www.goluckyvip.com/tag/30796.html
对外贸易之家:https://www.goluckyvip.com/tag/30797.html
敦豪集团:https://www.goluckyvip.com/tag/30798.html
Twitter和Meta的付费认证服务值得购买吗?:https://www.kjdsnews.com/a/1836404.html
零售晚报:携程发布318成绩单 近800万商家GMV增长101% :https://www.kjdsnews.com/a/1836405.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流