How to check if the IOS app is running for the first time using SWIFT -
this question has answer here:
- how detect first time app launch on iphone 12 answers
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { if ([[nsuserdefaults standarduserdefaults] boolforkey:@"haslaunchedonce"]) { // app launched } else { [[nsuserdefaults standarduserdefaults] setbool:yes forkey:@"haslaunchedonce"]; [[nsuserdefaults standarduserdefaults] synchronize]; // first launch ever } return yes; }
i searched question , got many answers in objective-c. can me in swift? thank in advance.
try one
if(nsuserdefaults.standarduserdefaults().boolforkey("haslaunchedonce") { // app launched } else { // first launch ever nsuserdefaults.standarduserdefaults().setbool(true, forkey: "haslaunchedonce") nsuserdefaults.standarduserdefaults().synchronize() }
swift 3 version->
if (userdefaults.standard.bool(forkey: "haslaunchedonce")) { // app launched } else { // first launch ever userdefaults.standard.set(true, forkey: "haslaunchedonce") userdefaults.standard.synchronize() }
Comments
Post a Comment