Notifications in IOS8

稍微看了一下Session 713(Notification),這次主要在IOS8新增了一些功能,分別是:

  • User Notifications

  • Notification Actions

  • Remote Notifications

  • Location Notifications

Notification

首先,不管是使用 Remote 或者是 Local notification都必須要註冊,並且徵求使用者同意。

Notification types

Notification 的 type 也跟之前的 Push 一樣分為 Badge, Sound, Alert

Notification Action 數量

Notification 在不同的地方,顯示的Action數量也會不同

地方 手勢 Action數量
lock screen 向左滑 2 actions
notification center 向左滑 2 actions
banners 往下拉 2 actions
alertview 4 actions

Notification 主要步驟(三大步驟)

  1. Register Actions(註冊Actions)

    • Action

      (自定義Acation,包含他的Identifier, title, activationMode, destructive, authenticationRequired共五個屬性)

    • Category

      (把Actions group in Category裡,例如:郵件Category可以包含寫郵件,讀郵件,刪除郵件三種Action,如下面Table)

    • Settings

      (你的APP當然不是只有郵件Category,可能還有廣告Category,吃飯Category。用NSSet把這三個Category打包起來)

  2. Send push Notification or schedule local notification(發出通知)

  3. Handle Action
Category Actions
Invite Accept, Maybe, Decline
New mail Mark as Read, Trash
Tagged Like, Comment, Untag

此外一定要用大標標出來的是 Push payload 的限制由 256 Byte 增加到 2KB!!!

另外一個大標是 locNotification.region = CL_XX_Region 可以支援CL_XX_Region系列,XX可能是Circular,也可以是Beacon!!!

基礎通知link
1
2
3
4
5
6
7
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [[NSDate date] dateByAddingTimeInterval:60*60*24];
notification.alertBody = @"24 hours passed since last visit :(";
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
取消全部通知link
1
2
3
4
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
指定特定時間通知link
1
2
3
4
5
6
7
8
9
10
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay: 3];
[components setMonth: 7];
[components setYear: 2012];
[components setHour: 6];
[components setMinute: 0];
[components setSecond: 0];
[calendar setTimeZone: [NSTimeZone defaultTimeZone]];
NSDate *dateToFire = [calendar dateFromComponents:components];

另外這篇有提到update alert body every day on local notification ???Notification的上限為64

target 的 Identity (Version, Build)

位於[[NSBundle mainBundle] infoDictionary]的

CFBundleShortVersionString < == > Version

CFBundleVersion < == > Build