alarm项目总结报告

一.目的

1.巩固所学

alarm实现所需要用到的知识都是之前所涉及了解过的,在实现alarm的过程中可以将之前所了解的知识运用到实践当中,由此对知识进行巩固和进一步熟悉.

2.掌握新知识

在完成项目的过程中避免不了出现一些功能用现有的知识无法实现,激励自己去查找资料或者通过他人的帮助来了解新的技术.能够更快更好的掌握新技术.

�二.过程

1.所用的核心技术

alarm的实现主要用的是iOS的本地推送功能:UILocalNotification

-(UILocalNotification *)notificationWithTime:(NSDate *)time {
NSMutableArray *musicArray = [model musiclistadd];
AlarmCount *shareCount = [AlarmCount shareCount];
NSDate *date = [self.datePicker date];
UILocalNotification *notifity=[[UILocalNotification alloc] init];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *timer = [formatter stringFromDate:time];
NSLog(@"%@",timer);
notifity.fireDate= [formatter dateFromString:timer];
notifity.timeZone=[NSTimeZone defaultTimeZone];
notifity.repeatInterval=  kCFCalendarUnitWeek ;
notifity.alertBody=@"时间到了";
notifity.soundName= musicArray[shareCount.bCount];
notifity.alertAction = @"打开";
NSString *key = [formatter stringFromDate:date];
NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"111" forKey:key];
[[UIApplication sharedApplication] scheduleLocalNotification:notifity];
notifity.userInfo = userDict;
return notifity;
}

上面的代码在系统中加了一个推送:
fireDate属性是推送的时间;
repeatInterval属性是重复的周期如kCFCalendarUnitWeek是一周重复一次,还可以设置为每天重复每年重复等等;
alertBody属性是推送的内容;
soundName属性是推送时播放的音乐;
userInfo属性可以设置一些这个推送的信息或标记;

值得注意的是推送会一直存在在系统中,不再需要的时候需要移除
移除有两种方式:
一种是直接全部代码如下:

[[UIApplication sharedApplication] cancelAllLocalNotifications];

另一种就可以根据userInfo移除指定的推送,代码如下:

for (UILocalNotification *notification in localNotifications) {
        NSDictionary *userInfo = notification.userInfo;
        if (userInfo) {
            // 根据设置通知参数时指定的key来获取通知参数
            NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
            [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
            NSString *key = [formatter stringFromDate:dateArray[shareCount.tablerow]];
            NSString *info = [userInfo objectForKey:key];
            // 如果找到需要取消的通知,则取消
            if (info != nil) {
                [[UIApplication sharedApplication] cancelLocalNotification:notification];
            }
        }
    }

在我实现的过程中还遇到过这样一个问题:设置全部正确但是推送就是不显示,通过查阅资料最终了解到iOS 8因为改变了推送消息的注册方式,所以在有推送需求的应用开发时,需要有些与以前不同的修改。可以在appDelegate.m文件的didFinishLaunchingWithOptions方法中加入下面一段代码:

#ifdef __IPHONE_8_0 //这里主要是针对iOS 8.0,相应的8.1,8.2等版本各程序员可自行发挥,如果苹 果以后推出更高版本还不会使用这个注册方式就不得而知了……
if ([[UIApplication sharedApplication]    respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings     settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotification    TypeAlert categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}  else {
    UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge |     UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
}
#else
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge |     UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
#endif

除了本地推送的运用之外也用到了单例进行传值:
+ (id)sharedInstance
{
static id sharedInstance;
static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{  
        sharedInstance = [[NSObject alloc] init];  
    });  
  
    return sharedInstance;  
} 

传值的问题也纠结了比较久的时间,所幸最后在范航的帮助下才成功.

剩下的就是一些之前接触过的东西uitableview,nsdate,presentViewController,排序,Tab Bar Controller等等就不一一诉说了.

下面附上一些alarm的运行截图:

alarm项目总结报告_第1张图片
alarm项目总结报告_第2张图片
alarm项目总结报告_第3张图片
alarm项目总结报告_第4张图片
alarm项目总结报告_第5张图片

后续

目前alarm还有许多不足:
从界面上来说,本次主要注重功能的实现所以说界面是相当简陋的,有待后续的改进.
从实现方式来说也是有所不足,比如通过ui界面来控制逻辑是十分不可取的,要吸取这些经验以后改进.
从功能上来说作为一个闹钟只实现了十分基本的功能,并没有实现所参照的walk me up里面的一些炫酷的功能.
从项目整体上来说前期的规划没有做好,导致实现的时候不断的返工,或者漏掉功能没有实现掉过头去添加的时候十分麻烦.

累积经验,争取以后做得更好.

你可能感兴趣的:(alarm项目总结报告)