objective c - How can I programmatically determine if my OSX app was launched from the Applications dir? -


i've built app osx , built .dmg installer it. however, users have trouble following huge arrow in background image telling them drag app /applications folder. ;-)

i nice if it's possible following:

  1. somehow detect if app launched /applications dir
  2. if wasn't, offer automatically move app dmg /applications dir, user, , launch there
  3. if #2 isn't os allow, display alert , close down app.

i can figure out #3 on own, i'm wondering if #1 , #2 possible , how might go them.

[nsbundle mainbundle] represents application bundle. can use app's url.

you can use nsurl volume information app's url , determine if launched within dmg. e.g.:

nsurl* bundleurl = [[nsbundle mainbundle] bundleurl]; nsstring* volumename = nil; if ([bundleurl getresourcevalue:&volumename forkey:nsurlvolumenamekey error:nil]) {     if ([volumename isequal:@"my app installer"]) // or whatever dmg volume name     {         [self trymigratingtoappsfolder];     } } 

or, check if it's not in /applications. keep in mind people install apps in different locations.

a full list of nsurl's available volume resources is available here.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -