4

我正在使用 Phonegap for ios 构建一个简单的闹钟,并且我已经在后台和前台触发了通知。(在 Drew Dahlman 和本教程 http://www.drewdahlman.com/meusLabs/?p=84的帮助下)。

phonegap 插件提供了在触发 localNotification 时运行后台和前台功能的能力。

我的问题是,如果应用程序在后台,我似乎只会得到一个默认的“关闭/查看”对话框,而不是我正在设置的通知对话框。我希望让后台通知让用户能够“起床”或“打盹”,但当然,这对于默认的“关闭/查看”通知是不可能的。

我错了吗?还有其他方法吗?

我设置本地通知的代码很简单

plugins.localNotification.add({ date: set_alarm,
                               消息:“背景”,  
                               徽章:1,
                               编号:12,
                               声音:'Alarm_01.caf',
                               背景:'MyApp.Alarm.notification_background',
                               前景:'MyApp.Alarm.notification_foreground'
                             });

前台通知工作正常,这只是我正在努力解决的后台通知。

4

1 回答 1

0

在您的应用程序 delegate.m 文件中,您需要在应用程序进入后台时激活警报或本地通知:

- (void)applicationDidEnterBackground:(UIApplication *)application

或者

- (void)applicationWillResignActive:(UIApplication *)application

(取决于您的需要)可以在此处找到更多文档:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html

我的怀疑是您仅将应用程序配置为在之后触发–application:didFinishLaunchingWithOptions:警报 -application:didReceiveLocalNotification:

这是默认设置。

还有许多其他选择:

监控应用状态变化

  • 应用程序:willFinishLaunchingWithOptions:
  • 应用程序:didFinishLaunchingWithOptions:
  • applicationDidBecomeActive:
  • applicationWillResignActive:
  • applicationDidEnterBackground:
  • 应用程序WillEnterForeground:
  • 应用程序将终止:
  • applicationDidFinishLaunching:

管理应用状态恢复

  • 应用程序:应该保存应用程序状态:
  • 应用程序:应该恢复应用程序状态:
  • 应用程序:viewControllerWithRestorationIdentifierPath:编码器:
  • 应用程序:willEncodeRestorableStateWithCoder:
  • 应用程序:didDecodeRestorableStateWithCoder:

为 Storyboard 窗口属性提供一个窗口 管理默认界面方向

  • 应用程序:supportedInterfaceOrientationsForWindow:

打开 URL 资源

  • 应用程序:openURL:源应用程序:注释:
  • 应用程序:handleOpenURL:

管理状态栏更改

  • 应用程序:willChangeStatusBarOrientation:持续时间:
  • 应用程序:didChangeStatusBarOrientation:
  • 应用程序:willChangeStatusBarFrame:
  • 应用程序:didChangeStatusBarFrame:

响应系统通知

  • applicationDidReceiveMemoryWarning:
  • applicationSignificantTimeChange:

处理远程通知

  • 应用程序:didReceiveRemoteNotification:
  • 应用程序:didRegisterForRemoteNotificationsWithDeviceToken:
  • 应用程序:didFailToRegisterForRemoteNotificationsWithError:

响应内容保护更改

  • applicationProtectedDataWillBecomeUnavailable:
  • applicationProtectedDataDidBecomeAvailable:
于 2012-12-19T14:41:25.080 回答