sindresorhus / LaunchAtLogin-Legacy

Add “Launch at Login” functionality to your macOS app in seconds
MIT License
1.55k stars 122 forks source link

App doesn't start on login #11

Closed nadia-dev closed 4 years ago

nadia-dev commented 6 years ago

I installed the framework using Carthage and set LaunchAtLogin.isEnabled = true on button click. But my app doesn't start at login. Is there something I am missing?

deadcoder0904 commented 6 years ago

Hey @nadia-dev I got it working with Carthage as well as CocoaPods.

You can find both projects here. The projects are very simple & are working well. Do check them out. Also, let me know if you face any issues.

Using Carthage - https://github.com/deadcoder0904/LaunchAtLoginCart

Using CocoaPods - https://github.com/deadcoder0904/LaunchAtLoginPod

ruohki commented 5 years ago

Doenst work for me either, not even the freshly cloned cocoapod repo

deadcoder0904 commented 5 years ago

@ruohki Weird I am using this in my AFK app plus Net Alert app & those 2 above solutions.

So if you have any errors other than vague "Doesn't work" I can help you :)

ruohki commented 5 years ago

I just started that mac dev stuff thats why i choosed this solution. With doesnt work i mean. Does not start, does not throw any errors.

import LaunchAtLogin

print(LaunchAtLogin.isEnabled)
//=> false

LaunchAtLogin.isEnabled = true

print(LaunchAtLogin.isEnabled)
//=> true

does its stuff but does not start the application on login.

Exported it with every option xcode gives me.

deadcoder0904 commented 5 years ago

I also started it like a month ago but got this working after some initial issues

import LaunchAtLogin

print(LaunchAtLogin.isEnabled)
//=> false

LaunchAtLogin.isEnabled = true

print(LaunchAtLogin.isEnabled)
//=> true

If this is working then it should work 👆

Try my examples above (if that doesn't work, sorry I can't help you)👇

Using Carthage - https://github.com/deadcoder0904/LaunchAtLoginCart

Using CocoaPods - https://github.com/deadcoder0904/LaunchAtLoginPod

ruohki commented 5 years ago

no the examples wont work.

running the latest xcode and macos

On Wed, Oct 10, 2018 at 8:55 AM Akshay Kadam (A2K) notifications@github.com wrote:

I also started it like a month ago but got this working after some initial issues

import LaunchAtLogin print(LaunchAtLogin.isEnabled)//=> false LaunchAtLogin.isEnabled = true print(LaunchAtLogin.isEnabled)//=> true

If this is working then it should work 👆

Try my examples above (if that doesn't work, sorry I can't help you)👇

Using Carthage - https://github.com/deadcoder0904/LaunchAtLoginCart

Using CocoaPods - https://github.com/deadcoder0904/LaunchAtLoginPod

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sindresorhus/LaunchAtLogin/issues/11#issuecomment-428459136, or mute the thread https://github.com/notifications/unsubscribe-auth/AF4PTmUTI6Dkz-IXoSj45cbZZjQCl_o6ks5ujZn1gaJpZM4VhGB4 .

andrewbranch commented 5 years ago

I'm experiencing the same thing macOS Mojave, installing via CocoaPods. In both my own app and the example app, if I find the helper app in the package contents and try to open it, it says

You can’t open the application “LaunchAtLoginHelper” because it may be damaged or incomplete.

timojaask commented 5 years ago

I'm running Mojave 10.14.2 and it does not start at login, even though LaunchAtLogin.isEnabled is returning true.

dbolger commented 5 years ago

I'm also having this issue @sindresorhus. The application I'm writing seems to enable the Login at launch, but the Login Items never update and it certainly does not start on login.

ruohki commented 5 years ago

Probably its simply not updated and tested for mojhave

Von meinem iPhone gesendet

Am 03.01.2019 um 22:28 schrieb Dylan Bolger notifications@github.com:

I'm also having this issue @sindresorhus. The application I'm writing seems to enable the Login at launch, but the Login Items never update and it certainly does not start on login.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

sindresorhus commented 5 years ago

but the Login Items never update

That's working as intended (by Apple). The "Login Items" are not updated with this API. There's no way to do so when sandboxed. I don't know why Apple chose to do it this way, but there's not much we can do about it.

sindresorhus commented 5 years ago

Probably its simply not updated and tested for mojhave

It is. I'm using this in my own apps which are updated for and tested on Mojave.

dbolger commented 5 years ago

That's working as intended (by Apple). The "Login Items" are not updated with this API. There's no way to do so when sandboxed. I don't know why Apple chose to do it this way, but there's not much we can do about it.

I didn't realize that it doesn't actually add them to the user's Login Items. It still doesn't seem to automatically launch the desired application though.

I also am having the same output from Xcode as the user in #21 has; I don't know if it's supposed to work in Xcode and it would make sense if it didn't.

g1eny0ung commented 5 years ago

I also face this problem. Finally, I solved it. Maybe the steps of debugging can help everyone who has this problem in development.

First, I set LaunchAtLogin.isEnabled = true from check button state:

if newOpenAtLoginState == .on {
    defaults.set(true, forKey: "openAtLogin")
    LaunchAtLogin.isEnabled = true
} else {
    defaults.set(false, forKey: "openAtLogin")
    LaunchAtLogin.isEnabled = false
}

After I set that, even though I reopen the app several times, the LaunchAtLogin.isEnabled always be false.

After searching by google, I find two helpful links:

https://stackoverflow.com/questions/44030354/macos-swift-how-to-properly-add-application-as-login-item/44352081#44352081 https://stackoverflow.com/questions/50417312/implemented-helper-app-but-does-not-launch-on-login/50515731#50515731

The first said:

For the ServiceManagement approach, sometimes it doesn't work in your development machine because there is another copy of the app in your Xcode's DerivedData.

So I clean up the DerivedData folder, but not working.

Then I switch to the second, the answer tells me to check system.log.

I search my app name and I find this:

Jan 11 14:35:07 yangyuedeMacBook-Pro com.apple.xpc.launchd[1] (org.ilime.GoalHubNext-LaunchAtLoginHelper[397]): removing service since it exited with consistent failure - OS_REASON_CODESIGNING | When validating /Users/g1eny0ung/Library/Developer/Xcode/Archives/2019-01-04/GoalHubNextProd 2019-1-4, 10.51 PM.xcarchive/Products/Applications/GoalHub.app/Contents/Library/LoginItems/LaunchAtLoginHelper.app/Contents/MacOS/LaunchAtLoginHelper:

After I clean up the Archives and all work fine. ~

This is the code I wrote:

https://github.com/ilime/GoalHub/blob/next/GoalHubNext/PreferenceViewController%2BAction.swift#L85

The solution of mine may not be cover all Open At Login problems. But I think it can help you to debug your app correctly.

dbolger commented 5 years ago

Compiling with Carthage seemed to work with me sometimes(?). The first time I kept getting the same error, the second time seemed to work. I somehow managed to remove the framework in my project, so I had to recompile and sure enough, the first time I was getting an error that the script didn't exist at the path (which it did, weird) and finally I was able to reimplement it with no errors onwards. :)

lcharette commented 5 years ago

I tried @g1eny0ung solution, without any luck.

Different error in System.log :

Jan 19 10:23:19 iMac-de-Louis com.apple.xpc.launchd[1] (com.foo.Bar-LaunchAtLoginHelper[527]): Could not find and/or execute program specified by service: 2: No such file or directory: com.foo.Bar-LaunchAtLoginHelper
Jan 19 10:23:19 iMac-de-Louis com.apple.xpc.launchd[1] (com.foo.Bar-LaunchAtLoginHelper[527]): Service setup event to handle failure and will not launch until it fires.
Jan 19 10:23:19 iMac-de-Louis com.apple.xpc.launchd[1] (com.foo.Bar-LaunchAtLoginHelper[527]): Service exited with abnormal code: 78

Installed using Pods. Tried on non-dev Mac with same error. I'll checkout other example to see what I may have done wrong, but if it can help others or if anyone has an idea where to look on my side.

lcharette commented 5 years ago

I tried @deadcoder0904 LaunchAtLoginPod and ended up with the same issue as before. After more unsuccessful debugging, I switched to Carthage and now everything works...

rkbhochalya commented 5 years ago

It didn't work for me as well until I switched to legacy build system in Xcode. I'm using Xcode 10.1 on macOS 10.14.3. I installed the framework using Carthage.

odinsride commented 5 years ago

Can't get this working either, using Carthage and Xcode 10.3 on Mojave. Print statements would make me think it's working fine, but my app doesn't start on login. Getting the following message in system.log:

Aug 14 12:48:51 Kevins-MacBook-Pro com.apple.xpc.launchd[1] \
(com.apple.xpc.launchd.user.domain.501.101317.Aqua): \
Could not import service from caller: caller = otherbsd.22137, \
service = org.olu.WallSwap-LaunchAtLoginHelper, error = 119: Service is disabled
sindresorhus commented 4 years ago

I added some debugging tips to the readme: https://github.com/sindresorhus/LaunchAtLogin#my-app-doesnt-launch-at-login-when-testing I'm happy to add more.