每當用戶推送通知,點擊該方法被調用
FUNC application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]
,fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)
但如果應用程序是越來越推出,並同時推來同樣的方法被調用。如何識別應用程序是否啓動或用戶單擊圖標以在前臺獲取應用程序。 這樣我就可以忽略推送通知過程。推送通知方法獲得的啓動應用程序的時候調用
0
A
回答
0
在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (launchOptions != nil)
{
// Here app will open from pushnotification
//RemoteNotification
NSDictionary* dictionary1 = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
//LocalNotification
NSDictionary* dictionary2 = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (dictionary1 != nil)
{
//RemoteNotification Payload
//set your function to handle notification
NSLog(@"Launched from push notification: %@", dictionary1);
}
if (dictionary2 != nil)
{
NSLog(@"Launched from dictionary2dictionary2dictionary2 notification: %@", dictionary2);
double delayInSeconds = 7;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// [self addMessageFromRemoteNotification:dictionary2 updateUI:NO];
});
}
}
else
{}
在- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if(application.applicationState == UIApplicationStateInactive) {
NSLog(@"Inactive - the user has tapped in the notification when app was closed or in background");
//do some tasks
}
else if (application.applicationState == UIApplicationStateBackground) {
NSLog(@"application Background - notification has arrived when app was in background");
NSString* contentAvailable = [NSString stringWithFormat:@"%@", [[userInfo valueForKey:@"aps"] valueForKey:@"content-available"]];
if([contentAvailable isEqualToString:@"1"]) {
// do tasks
NSLog(@"content-available is equal to 1");
}
}
else {
NSLog(@"application Active - notication has arrived while app was opened");
//Show an in-app banner
//do tasks
}
相關問題
- 1. 任何推送通知時啓動應用程序的方法?
- 2. 通過推送通知啓動調試應用程序
- 3. Air iOS/Android推送通知記得應用程序啓動
- 4. 使用推送通知啓動時應用程序崩潰
- 5. 推送通知每次在應用程序啓動時顯示
- 6. Android,使用parse.com推送通知,自動啓動應用程序
- 7. Wp7推送通知啓動我的應用程序
- 8. Iphone4的推送通知和啓動應用程序
- 9. 從推送通知的警報視圖啓動應用程序
- 10. 通過Android推送通知啓動應用程序
- 11. 如何在應用未啓動時調試推送通知?
- 12. 當推送通知進入時被調用的方法序列
- 13. 如何啓用/禁用應用程序的推送通知?
- 14. Trigger.IO:知道什麼時候通過推送通知打開應用程序
- 15. Android應用程序的推送通知
- 16. 推送iPhone應用程序的通知
- 17. 在應用啓動時獲取推送通知詳細信息
- 18. 在推送通知期間啓動待機應用程序
- 19. 如何從應用內程序啓動iOS推送通知
- 20. 報亭推送通知不會啓動應用程序
- 21. 如何獲得啓動的任何應用程序的通知
- 22. 推送通知不調用方法
- 23. 當應用程序未啓動時使用Phonegap和Pushwoosh推送通知
- 24. 使用Process.Start()方法啓動應用程序後的通知
- 25. 當應用程序未運行時獲取推送通知iPhone
- 26. 應用程序更新推送通知
- 27. 從應用程序推送通知
- 28. iPhone應用程序推送通知
- 29. 推送通知web應用程序
- 30. 發佈推送通知應用程序