Dev*_*fly 39 cocoa-touch apple-push-notifications uiapplicationdelegate ios
application: didReceiveRemoteNotification: fetchCompletionHandler:
Run Code Online (Sandbox Code Playgroud)
不同于
application: didReceiveRemoteNotification:
Run Code Online (Sandbox Code Playgroud)
怎么样?来自文档:
与应用程序:didReceiveRemoteNotification:方法不同,只有在应用程序运行时才会调用该方法,系统会调用此方法,而不管应用程序的状态如何.如果您的应用暂停或未运行,系统会在调用该方法之前唤醒或启动您的应用并将其置于后台运行状态.如果用户从系统显示的警报中打开您的应用程序,系统将再次调用此方法,以便您知道用户选择了哪个通知.
我的斗争是:我想知道用户是否通过从通知中心点击系统显示的警报或从唤醒设备的静默推送通知来调用该方法.目前,据我所知,没有明显的区分方法.
- (BOOL)application: didFinishLaunchingWithOptions:
Run Code Online (Sandbox Code Playgroud)
跟踪上述方法中的launchOptions不是一个解决方案,因为只有在应用程序暂停/未在后台运行时才会调用它.如果它在后台运行则不会被调用.
rac*_*arr 41
Apple文档有点令人困惑
application: didReceiveRemoteNotification: fetchCompletionHandler:
Run Code Online (Sandbox Code Playgroud)
如果您的应用程序支持远程通知后台模式(即您正在执行BackgroundFetch),则使用此方法.
application: didReceiveRemoteNotification:
Run Code Online (Sandbox Code Playgroud)
当操作系统收到RemoteNotification并且应用程序正在运行时(在后台/暂停或在前台),
可以调用.您可以检查UIApplicationState以查看应用程序是否被用户带到前台(点击通知)或已经通知进来时运行.
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIApplicationState state = [application applicationState];
// user tapped notification while app was in background
if (state == UIApplicationStateInactive || state == UIApplicationStateBackground) {
// go to screen relevant to Notification content
} else {
// App is in UIApplicationStateActive (running in foreground)
// perhaps show an UIAlertView
}
}
Run Code Online (Sandbox Code Playgroud)
Riv*_*era 18
您可以检查UIApplication的applicationState区分与应用程序正在积极使用由用户进行通话无声的召唤:
typedef enum : NSInteger {
UIApplicationStateActive,
UIApplicationStateInactive,
UIApplicationStateBackground
} UIApplicationState;
Run Code Online (Sandbox Code Playgroud)
或保持对自己的标志设置delegate的applicationDidEnterBackground:.
小智 9
应用程序状态不可靠,因为如果您的应用程序打开了控制中心或Apple的通知中心,则应用程序:didReceiveRemoteNotification:fetchCompletionHandler:将被调用,应用程序状态将处于非活动状态.
我有同样的问题,试图在应用程序处于后台时响应点击通知,并且似乎没有可靠的方法来单独识别这一点.
| 归档时间: |
|
| 查看次数: |
28548 次 |
| 最近记录: |