How to open the app from the background task in iOS?

gjrwebber

Is it possible to open an app from a background task in iOS?

I want my app to run in the background, and I want it to reappear for whatever reason without user input. Is this possible?

In Android you can have a service that runs in the background, and at any time you can start an Activity, which starts the app for that activity.

I know this does not make for a good user experience. I still want to know whether it can be done.

John Ballinger

You can create schedule a local notification with a time offset of 0 (eg show an alert immediatly). If the use taps on the notification, the app will be launched.

But otherwise, you will not be able to launch out of the background into the forground without a notification.

    NSDate * theDate = [[NSDate date] dateByAddingTimeInterval:0]; //

    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];
    if (alarm)
    {
        alarm.fireDate = theDate;
        alarm.timeZone = [NSTimeZone defaultTimeZone];
        alarm.repeatInterval = 0;
        alarm.soundName = @"sonar";
        alarm.alertBody = @"Background task complete, tap to show app" ;

        [app scheduleLocalNotification:alarm];
    }

From Apples Documentation: "Notifications are a way for an app that is suspended, is in the background, or is not running to get the user’s attention. 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. (If the app is already running in the foreground, local notifications are delivered quietly to the app and not to the user.)"

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Open Apple Maps App With Directions from my ios App iOS 9 Swift 2.2

来自分类Dev

Register Background Task in Silverlight 8.1 app

来自分类Dev

How to upload DevExtreme ios app from windows?

来自分类Dev

iOS/Objective-C - How do I query a web server database from an iPhone app?

来自分类Dev

Subscribing email address to MailChimp from iOS app

来自分类Dev

使用终端命令'open -n -a“ iOS Simulator”'运行多个iOS Simulator.app

来自分类Dev

Execute task in background in WPF application

来自分类Dev

How to get APNS push notification in background in iOS6?

来自分类Dev

swift2 how to log when app is in background?

来自分类Dev

How to start mobile app from wear app?

来自分类Dev

How to update the screenshot of an app on IOS 7

来自分类Dev

How to disable automatic app scaling in iOS 8?

来自分类Dev

iOS萤幕撷取画面为Background App中的System.Drawing.Bitmap(Xamarin)

来自分类Dev

为什么 iOS 静默推送会触发 application:didFinishLaunchingWithOptions: when app is in background

来自分类Dev

How to wake up a FreeRtos task from a high priority ISR?

来自分类Dev

share image on twitter and get favourites list from iOS native app

来自分类Dev

OPEN CV iOS安装

来自分类Dev

bash command substitution on a script that executes a background task

来自分类Dev

Run frequent background task on Windows Phone 8.1

来自分类Dev

Execution failed for task ':app:compileDebugKotlin'

来自分类Dev

How do I remove the background from this kind of image?

来自分类Dev

Can't copy MS Word document to my app from iOS Word app

来自分类Dev

How to set an image title in the navigation bar of an iOS app

来自分类Dev

How to implement main.swift in Xcode 6 iOS app?

来自分类Dev

How to integrate Facebook User's Newsfeed (or) Wall post in iOS App

来自分类Dev

How did Pebble official iOS app to get incoming call number?

来自分类Dev

How can I debug an iOS app executed in mobile not launched by Xcode?

来自分类Dev

How to retrieve multiple objects from Parse for iOS

来自分类Dev

How to get the id of a chrome app from an extension

Related 相关文章

  1. 1

    Open Apple Maps App With Directions from my ios App iOS 9 Swift 2.2

  2. 2

    Register Background Task in Silverlight 8.1 app

  3. 3

    How to upload DevExtreme ios app from windows?

  4. 4

    iOS/Objective-C - How do I query a web server database from an iPhone app?

  5. 5

    Subscribing email address to MailChimp from iOS app

  6. 6

    使用终端命令'open -n -a“ iOS Simulator”'运行多个iOS Simulator.app

  7. 7

    Execute task in background in WPF application

  8. 8

    How to get APNS push notification in background in iOS6?

  9. 9

    swift2 how to log when app is in background?

  10. 10

    How to start mobile app from wear app?

  11. 11

    How to update the screenshot of an app on IOS 7

  12. 12

    How to disable automatic app scaling in iOS 8?

  13. 13

    iOS萤幕撷取画面为Background App中的System.Drawing.Bitmap(Xamarin)

  14. 14

    为什么 iOS 静默推送会触发 application:didFinishLaunchingWithOptions: when app is in background

  15. 15

    How to wake up a FreeRtos task from a high priority ISR?

  16. 16

    share image on twitter and get favourites list from iOS native app

  17. 17

    OPEN CV iOS安装

  18. 18

    bash command substitution on a script that executes a background task

  19. 19

    Run frequent background task on Windows Phone 8.1

  20. 20

    Execution failed for task ':app:compileDebugKotlin'

  21. 21

    How do I remove the background from this kind of image?

  22. 22

    Can't copy MS Word document to my app from iOS Word app

  23. 23

    How to set an image title in the navigation bar of an iOS app

  24. 24

    How to implement main.swift in Xcode 6 iOS app?

  25. 25

    How to integrate Facebook User's Newsfeed (or) Wall post in iOS App

  26. 26

    How did Pebble official iOS app to get incoming call number?

  27. 27

    How can I debug an iOS app executed in mobile not launched by Xcode?

  28. 28

    How to retrieve multiple objects from Parse for iOS

  29. 29

    How to get the id of a chrome app from an extension

热门标签

归档