Launch macOS app from FinderSync extension - swift

I wrote an app that implements FinderSync extension.
Everything works fine, I can "communicate" by sending notifications through DistributedNotificationCenter from extension to main app. But obviously it works if the main app is running only.
Is there any mechanism to open terminated app and pass parameters?
UPDATE:
The idea is to implement simple image processing app. I want to run the main app (containing execution code and GUI) from Finder-Sync extension.
To be more specific I implemented func menu(for menu: FIMenuKind) -> NSMenu? of FIFinderSyncProtocol and I want to run/open main app when user right-clicks the menu item and selects operation I added into menu.

As I guess that my comment is at least somewhat valid, I'll put it in the answer.
Extensions allow launching of the main app by using the URL that app handles.
Communication with URL may not be enough, but you can have the app group where extension could write the data to disk and be readable by the main app or use your current way of communication with some adaptations to this method.

You can use SMLoginItemSetEnabled to launch background "helper" application.
https://developer.apple.com/documentation/servicemanagement/1501557-smloginitemsetenabled
This helper app can be launched in the background by a sandboxed app with few restrictions, and kept open when then main app closes. Your FinderSync extension can continue to communicate with the helper app even if the main app is closed.

Related

LaunchScreen storyboard is it mandatory for App Store app

I coded my app with several ViewControllers including an initial WelcomeVC. My app works well and I have no delay when launching it. I have seen that LaunchScreen.storyboard is used for first screen when app is launched but I don't need it in my app. I want to use it and submit it this way to the App Store without LaunchScreen. Do you know if this is possible?
Nevertheless I tried to add a simple LaunchScreen but I see no utility as on my Iphone when the App starts it goes so quick that I don't see the LaunchScreen.
Can I post an app without LaunchScreen?
Can I post an app without LaunchScreen?
No. Well, you can post it, but it will be rejected.
The launch screen does more than just provide an interim screen during launch. It also acts as a signal so that the device knows your app can adapt to it. Therefore Apple now requires (or soon will require) that an app submitted to the app store have a launch screen.

How to embed a cocoa app in another cocoa app and launch it as a subprocess

I want to embed a App A in another App B. When App A is launched it should act as a wrapper and internally launch App B without showing App B in docbar.Purpose of App A is just a wrapper ,it should do some initialisation to launch App B depending from where it is getting launched
In your project, build both apps using separate targets.
In App A > Target > Build Phases:
Add App B to the Target Dependancies
Add the product of App B to the Copy Bundle Resources phase.
Now when you build App A, Xcode will build App B and copy the finished App B into the Resources folder of App A's bundle.
You don't explain why you want to do this, so here are some ideas to get you started...
Option A:
Use the NSBundle class to locate the embedded App B and launch it however you see fit (directly, using launchd, etc.).
If you don't want App B to show up in the dock or have a menu bar, you need to set the LSUIPresentationMode in the app's Info.plist or adjust the app's activationPolicy property programatically.
Option B:
Consider creating an XPC Service. An XPC services is a special embedded executable that macOS will launch for you whenever you need it and set up an XPC connection for you so you can talk to it and do work.
See Creating XPC Services
XPC also has facilities so that a faceless (non-app) helper process can have a UI that appears in your app. (This is the way Safari works; each page is handled by a separate helper process, using XPC to control the page and present it in a Safari window.)

Library app Vs Standalone iPhone app

I am building a native iPhone application wherein this application will act as a standalone app on one device and act as a library on other device. Can you please guide me how should I design the app. Should the same method "applicationDidFinishedLaunching" be called in both the cases and just in the basis of some parameters I will be distinguishing from where the call was made. This is because, in both the cases, I have some different screen flows.
Library code has to be compiled into the running app to be used. No other app can access your code, as all apps are sandboxed and prohibited from accessing each other's directories, and thus any code contained in such. If someone taps on another icon, it will be as if your library code does not exist to that app.
Another app can start your app by using a registered launch URL, but that will just result in your app being brought to the foreground. The other app will be put into the background or terminated.

How to open a file with my app? (When my app is in the background)

My app reads some kind of file(*.mndl) and with below method I can open a file if other app requires it (Using the options parameter).
application:didFinishLaunchingWithOptions:
It works fine, but when my app is still alive in background and other app requires to open a file it won't happen since that method is not called anymore, instead applicationDidBecomeActive: and/or applicationWillEnterForeground:, etc are called
What options do I have?
I wouldn't like to terminate my app everytime I want to import some file from Mail.app from example. ;(
Thanks
I'm sure you've checked this out, but there's a good section on opening files in the documentation (link)
There's a section in there talking about using application:handleOpenURL: or application:openURL:sourceApplication:annotation: to open the file, perhaps that's what you're looking for?

iPhone App in suspended state, launched by URL, showing Default.png

The app responds to a custom URL, and correctly launches when in a suspended state. The question is, can I disable showing the Default.png when launched this way?
A use case for clarity:
app is started normally
a home button press puts app in standby
a url of the scheme the app recognizes is tapped in mobile safari
users sees Default.png before launch is complete.
As you probably know, when fast app switching activates usually the app is redisplayed with a screenshot of the last state rather than the Default.png. This is what I'd prefer happens when the URL launch takes place also.
It sounds like what is going on is that Fast App Switching is not actually working. So:
Make sure you are building the application for SDK for OS 4.0. If you don't, you app will not have fast app switching support.
See if fast app switching normally (otherwise) works with your application. I.E. when you just switch to safari, then re-launch your application, do you get the "default.png"?
Run the app under the debugger, but on your actual device. Make the problem happen, go into the Organizer, and look under device logs. This will show you if there was a low-memory issue which caused your application to be terminated, when Safari was launched, thus requiring it to be re-launched when the URL was selected.
I believe there were two mechanisms in place. In my app, I do not support "Launch with URL" - but what I do do is support the Application Delegate's call:
-(BOOL) application:(UIApplication *) application handleOpenURL:(NSURL *) url {
This may be the difference - this is the call which can be made to an application that is running to hand it a URL to process. If you are using the other technique, use this one instead. I use this, and do not see the "default.png" - i.e. do not evoke a "clean relaunch" when I get called.
Here's a possible workaround. This was causing me a headache with trying to seamlessly return from Facebook's single sign on process. I wanted the appearance of going back to my app's login area, instead of the appearance of restarting the app, even though I verified in every way possible that the app was indeed returning from fast app switching and not actually restarting.
While I couldn't find any way to force the app to display the previous state's screenshot, I did discover that the app will display Default-scheme.png (for example, Default-fb12345.png or Default-appname.png) when invoked with a url. So if your post-app switching screenshot is fairly predictable, grab a screenshot from iOS Simulator and copy it into your app. I would consider this an iOS bug. The app should always display the last screenshot when app switching, rather than Default-scheme.png simply because a url is involved.
Another possibility, which I didn't test, would be to symlink the bundle's Default-scheme.png (and Default-scheme#2x.png) to the snapshot file in the app home directory. This would be Library/Caches/Snapshots/[Bundle identifier]/UIApplicationAutomaticSnapshotDefault-Portrait#2x.jpg for most situations (unless it's landscape, or an iPad). If your app's state is unpredictable but the orientation is fixed, this could be a good option to try.
Make sure you've got the "Required Background Modes" key set in the Info.plist to the function that the app needs. If it's not listed, I just use "App Plays Audio" to keep it open.