background and notification of local

Scheduling the Delivery of Local Notifications

Notifications are a way for an app that is suspended, is in the background, or is not running to get the user’s attention. 本地消息主要用于获得用户注意,可见方式有显示alert,播放声音,更新app icon的图表(显示一个数字)

Apps can use local notifications to display alerts, play sounds, badge the app’s icon, or a combination of the three. For example, an alarm clock app might use local notifications to play an alarm sound and display an alert to disable the alarm. 最典型的就是闹钟程序,播放声音,弹出警告框。When a notification is delivered to the user, the user must decide if the information warrants bringing the app back to the foreground. 用户可以决定是否把APP激活到前台,(If the app is already running in the foreground, local notifications are delivered quietly to the app and not to the user.)如果app本来在运行,消息会悄悄地发送到程序,而不是用户。

这悄悄地发给程序了,程序使用delegate’s application:didReceiveLocalNotification: 来接收到消息,也可以采取同样的行为,例如alert/播放sound

shows an example that schedules a single alarm using a date and time that is set by the user. This example configures only one alarm at a time and cancels the previous alarm before scheduling a new one. (Your own apps can have no more than 128 local notifications active at any given time, any of which can be configured to repeat at a specified interval.) The alarm itself consists of an alert box and a sound file that is played if the app is not running or is in the background when the alarm fires. 


- (void)scheduleAlarmForDate:(NSDate*)theDate
{
    UIApplication* app = [UIApplication sharedApplication];
    NSArray*    oldNotifications = [app scheduledLocalNotifications];
 
    // Clear out the old notification before scheduling a new one.
    if ([oldNotifications count] > 0)
        [app cancelAllLocalNotifications];
 
    // Create a new notification.
    UILocalNotification* alarm = [[[UILocalNotification alloc] init] autorelease];
    if (alarm)
    {
        alarm.fireDate = theDate;
        alarm.timeZone = [NSTimeZone defaultTimeZone];
        alarm.repeatInterval = 0;
        alarm.soundName = @"alarmsound.caf";
        alarm.alertBody = @"Time to wake up!";
 
        [app scheduleLocalNotification:alarm];
    }
}

比较贴近的:

Newsstand apps that need to download and process new content 内容杂志型的 app,需要下载和处理新内容的

Apps that receive regular updates from external accessories。经常受到外部设备的更新。。。。。。。。。

增加info配置,申明app后台一直执行长时间任务:XX-Info.plist-》UIBackgroundModes -》数组的item增加newsstand-content

  • newsstand-content—The app is a Newsstand app that downloads and processes magazine or newspaper content in the background.

  • external-accessory—The app works with a hardware accessory that needs to deliver updates on a regular schedule through the External Accessory framework.

以上的配置会使ios明白在合适的时间启动,响应相关的事件。例如播放声音的程序,在后台需要填充audio输出的buffers。

Each of the preceding values lets the system know that your app should be woken up at appropriate times to respond to relevant events. For example, an app that begins playing music and then moves to the background still needs execution time to fill the audio output buffers. Including the  audio key tells the system frameworks that they should continue playing and make the necessary callbacks to the app at appropriate intervals. 通过在info配置中加入audio,就使得系统定期通知app,app可以得到cpu事件,获取audio file内容。If the app does not include this key, any audio being played by the app stops when the app moves to the background.


Downloading Newsstand Content in the Background 通过后台下载内容

A Newsstand app that downloads new magazine or newspaper issues can register to perform those downloads in the background. When your server sends a push notification to indicate that a new issue is available, the system checks to see whether your app has the UIBackgroundModes key with the newsstand-content value. If it does, the system launches your app, if it is not already running, so that it can initiate the downloading of the new issue.

当你的远端服务器发送通知,告知程序新杂志到达时候,系统可以检查程序是否有newsstand-content 设置,如果有,系统会启动app(如果还没有运行的话),然后就会启动下载

When you use the Newsstand Kit framework to initiate a download, the system handles the download process for your app. 如g国使用NK框架初始化下载,The system continues to download the file even if your app is suspended or terminated 系统会负责下载内容的,即使app不在active. When the download operation is complete, the system transfers the file to your app sandbox and notifies your app(下载完成后,系统会接触你程序的sandbox,通知程序可以获得文件了). If the app is not running, this notification wakes it up and gives it a chance to process the newly downloaded file. 程序会被系统唤醒来处理这个通知,如果下载过程中有错误,系统也会通知程序处理此类错误If there are errors during the download process, your app is similarly woken up to handle them.

For information about how to download content using the Newsstand Kit framework, see Newsstand Kit Framework Reference.

其实目前来看,一个书架,上面有一些本地PDF,但还是要看发布者那边,如果有新的书,你可以接收下载(当然是通过NKF),这个story+PDF 编辑才能形成一个好的体验。

potential question,一体化的应用,第一财经为啥不这么干呢。。。。

参考:

http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW28

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值