Determine if iOS is the first time the app launches

Source: Internet
Author: User
<span id="Label3"></p><pre class="best-text mb-10">It's important to add some help or promotional animations to your First-run Application.<br>A useful example is to send an analysis instance. This may be a good way to determine how many people download utility Applications. Someone would say, "but, hey, Apple AppStore has told me that the app has downloaded a volume."<br><br>The popular solution is in most places with [nsuserdefaults<br>Standarduserdefaults a key if it does not exist, which means that this is an application startup, otherwise it is not the first Time. Then it says set the key to the latter in the Method: "applicationwillterminate: (uiapplication*) application". This solution is very good until we get the iOS<br>4.0. On iOS<br>4.0<br>+ This approach is rarely called (only for memory Problems) as described in Apple's uiapplicationdelegate documentation. ...<br><br>You can search for the key if it is not set to run First-time-code and set it, but in the rest of the app you will not know if it is the first run (unless you use a global Variable)<br><br>therefore, I recommend my solution: ...<br><br>Found in APPDELEGATE.M<br>"application:didfinishlaunchingwithoptions:" method, Add the following code:<br><br>If (![ [nsuserdefaults standarduserdefaults] boolforkey:@ "everlaunched"]) {<br>[[nsuserdefaults standarduserdefaults] Setbool:yes forkey:@ "everlaunched"];<br>[[nsuserdefaults standarduserdefaults] Setbool:yes forkey:@ "firstlaunch"];<br>}<br>else{<br>[[nsuserdefaults standarduserdefaults] setbool:no forkey:@ "firstlaunch"];<br>}<br><br>The total solution is 2 key: @ "everlaunched" to determine if the user has previously logged in,<br><br>@ "firstlaunch" is used by developers to judge in other parts of the Program.<br><br>At the first boot, key @ "everlaunched" is not assigned and is set to Yes. @ "firstlaunch" is set to YES.<br><br>In other parts of the program, use the following code to Determine:<br><br>If ([[[nsuserdefaults standarduserdefaults] boolforkey:@ "firstlaunch"]) {<br>Here to determine whether the first time<br>Uialertview *alert=[[uialertview alloc] initwithtitle:@ "first time"<br>message:@ "go to app"<br>Delegate:self<br>cancelbuttontitle:@ "i know."<br>otherbuttontitles:nil];<br>[alert show];<br>[alert release];<br><br>}<br><br>The first piece of code runs key<br>@ "firstlaunch" will be set to NO.<br><br><br><br>Reproduced for reference only, copyright belongs to the original author</pre><p><p>Determine if iOS is the first time the app launches</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.