存贮在keychainQuery 可以统计用户使用情况
<p style="font-size: 14px; line-height: normal; font-family: Menlo;">-(<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">void</span>)gatherMessage{</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: 'Heiti SC Light'; color: rgb(0, 132, 0);"><span style="font-family:Menlo;color:#000000;line-height: normal;">    </span><span style="font-family:Menlo;line-height: normal;">//</span>采集用户设备信息</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">    </span>NSUserDefaults<span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> *userDefaults=[</span>NSUserDefaults<span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span><span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">standardUserDefaults</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">];</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSDate</span> *loadDate=[<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSDate</span> <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">date</span>];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSDate</span> *lastData=[userDefaults <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">valueForKey</span>:<span style="color:#d12f1b;font-variant-ligatures: no-common-ligatures;">@"loadForDay"</span>];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">    </span>NSDateFormatter<span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> *dateFormatter=[[</span>NSDateFormatter<span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span><span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">alloc</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">]</span><span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">init</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">];</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    [dateFormatter <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">setDateFormat</span>:<span style="color:#d12f1b;font-variant-ligatures: no-common-ligatures;">@"YYYY/MM/dd"</span>];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span> *lastd=[dateFormatter <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">stringFromDate</span>:lastData];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span> *nowd=[dateFormatter <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">stringFromDate</span>:loadDate];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">if</span> (![lastd <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">isEqualToString</span>:nowd]) {</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        [userDefaults <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">setObject</span>:loadDate <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">forKey</span>:<span style="color:#d12f1b;font-variant-ligatures: no-common-ligatures;">@"loadForDay"</span>];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        <span style="color:#008400;font-variant-ligatures: no-common-ligatures;">//</span><span style="font-family:'Heiti SC Light';color:#0840;line-height: normal;">获取设备型号</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span> *deviceModel=[<span style="color:#4f8187;font-variant-ligatures: no-common-ligatures;">CommenData</span> <span style="color:#31595d;font-variant-ligatures: no-common-ligatures;">getCurrentDeviceModel</span>];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;">    </p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">        </span>//identifierForVendor <span style="font-family:'Heiti SC Light';line-height: normal;">作为唯一标识</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(61, 29, 129);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">        </span><span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> *identifierStr = [[[</span><span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">UIDevice</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span>currentDevice<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">] </span>identifierForVendor<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">] </span>UUIDString<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">];</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span> * <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">const</span> KEY_USERNAME_PASSWORD = <span style="color:#d12f1b;font-variant-ligatures: no-common-ligatures;">@"com.int-yt.kyks.usernamepassword"</span>;</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span> * <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">const</span> KEY_PASSWORD = <span style="color:#d12f1b;font-variant-ligatures: no-common-ligatures;">@"com.int-yt.kyks.password"</span>;</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSMutableDictionary</span> *usernamepasswordKVPairs = [<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSMutableDictionary</span> <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">dictionary</span>];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        [usernamepasswordKVPairs <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">setObject</span>:identifierStr <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">forKey</span>:KEY_PASSWORD];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;">    </p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSMutableDictionary</span> *readUserPwd = (<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSMutableDictionary</span> *)[<span style="color:#4f8187;font-variant-ligatures: no-common-ligatures;">CommenData</span> <span style="color:#31595d;font-variant-ligatures: no-common-ligatures;">load</span>:KEY_USERNAME_PASSWORD];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">if</span>(readUserPwd==<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">nil</span>){</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">            <span style="color:#008400;font-variant-ligatures: no-common-ligatures;">//</span><span style="font-family:'Heiti SC Light';color:#0840;line-height: normal;">存</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">            [<span style="color:#4f8187;font-variant-ligatures: no-common-ligatures;">CommenData</span> <span style="color:#31595d;font-variant-ligatures: no-common-ligatures;">save</span>:KEY_USERNAME_PASSWORD <span style="color:#31595d;font-variant-ligatures: no-common-ligatures;">data</span>:usernamepasswordKVPairs];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">            readUserPwd = (<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSMutableDictionary</span> *)[<span style="color:#4f8187;font-variant-ligatures: no-common-ligatures;">CommenData</span> <span style="color:#31595d;font-variant-ligatures: no-common-ligatures;">load</span>:KEY_USERNAME_PASSWORD];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;">          </p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        }</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">        </span>//<span style="font-family:'Heiti SC Light';line-height: normal;">调用接口纪录登陆信息</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;">        </p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">        </span><span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> *string= [</span><span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span><span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">stringWithFormat</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">:</span>@"%@cdpt/api/uselog?access_token=123&imeiid=%@&mtype=%@&device_platform=2"<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">,</span><span style="color:#4f8187;font-variant-ligatures: no-common-ligatures;">BaseURLString</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">, [readUserPwd </span><span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">objectForKey</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">:KEY_PASSWORD],deviceModel];</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;">        </p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSURL</span> *url = [<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSURL</span> <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">URLWithString</span>:string];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSURLRequest</span> *request = [<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSURLRequest</span> <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">requestWithURL</span>:url];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">NSLog</span>(<span style="color:#d12f1b;font-variant-ligatures: no-common-ligatures;">@"%@"</span>,string);</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">        </span>AFHTTPRequestOperation<span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> *operation = [[</span>AFHTTPRequestOperation<span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span><span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">alloc</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">] </span><span style="color:#31595d;font-variant-ligatures: no-common-ligatures;">initWithRequest</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">:request];</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">        operation.</span>responseSerializer<span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> = [</span>AFJSONResponseSerializer<span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span><span style="color:#31595d;font-variant-ligatures: no-common-ligatures;">serializer</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">];</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        [operation <span style="color:#31595d;font-variant-ligatures: no-common-ligatures;">setCompletionBlockWithSuccess</span>:^(<span style="color:#4f8187;font-variant-ligatures: no-common-ligatures;">AFHTTPRequestOperation</span> *operation, <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span> responseObject) {</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;">
</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        } <span style="color:#31595d;font-variant-ligatures: no-common-ligatures;">failure</span>:^(<span style="color:#4f8187;font-variant-ligatures: no-common-ligatures;">AFHTTPRequestOperation</span> *operation, <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSError</span> *error) {</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;">
</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        }];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        [operation <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">start</span>];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    }</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">}</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">//<span style="font-family:'Heiti SC Light';line-height: normal;">存</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">+ (<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">void</span>)save:(<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span> *)service data:(<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span>)data {</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">    </span>//Get search dictionary</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSMutableDictionary</span> *keychainQuery = [<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">self</span> <span style="color:#31595d;font-variant-ligatures: no-common-ligatures;">getKeychainQuery</span>:service];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">    </span>//Delete old item before add new item</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">SecItemDelete</span>((<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span> <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">CFDictionaryRef</span>)keychainQuery);</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">    </span>//Add new object to search dictionary(Attention:the data format)</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(61, 29, 129);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">    [keychainQuery </span>setObject<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">:[</span><span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSKeyedArchiver</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span>archivedDataWithRootObject<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">:data] </span>forKey<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">:(</span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">)</span><span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">kSecValueData</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">];</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">    </span>//Add item to keychain with the search dictionary</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">SecItemAdd</span>((<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span> <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">CFDictionaryRef</span>)keychainQuery, <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">NULL</span>);</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">}</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;">
</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">+ (<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSMutableDictionary</span> *)getKeychainQuery:(<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span> *)service {</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(61, 29, 129);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">    </span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">return</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> [</span><span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSMutableDictionary</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span>dictionaryWithObjectsAndKeys<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">:</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">            (</span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">)</span>kSecClassGenericPassword<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">,(</span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">)</span>kSecClass<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">,</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">            service, (<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span> <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span>)<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">kSecAttrService</span>,</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">            service, (<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span> <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span>)<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">kSecAttrAccount</span>,</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">            (</span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">)</span>kSecAttrAccessibleAfterFirstUnlock<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">,(</span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">)</span>kSecAttrAccessible<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">,</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">            <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">nil</span>];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">}</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;">
</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">//<span style="font-family:'Heiti SC Light';line-height: normal;">取</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">+ (<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span>)load:(<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span> *)service {</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span> ret = <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">nil</span>;</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSMutableDictionary</span> *keychainQuery = [<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">self</span> <span style="color:#31595d;font-variant-ligatures: no-common-ligatures;">getKeychainQuery</span>:service];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">    </span>//Configure the search setting</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">    </span>//Since in our simple case we are expecting only a single attribute to be returned (the password) we can set the attribute kSecReturnData to kCFBooleanTrue</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    [keychainQuery <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">setObject</span>:(<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span> <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span>)<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">kCFBooleanTrue</span> <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">forKey</span>:(<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span> <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span>)<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">kSecReturnData</span>];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">    [keychainQuery </span><span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">setObject</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">:(</span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">)</span>kSecMatchLimitOne<span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span><span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">forKey</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">:(</span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span><span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">id</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">)</span>kSecMatchLimit<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">];</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">CFDataRef</span> keyData = <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">NULL</span>;</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">if</span> (<span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">SecItemCopyMatching</span>((<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span> <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">CFDictionaryRef</span>)keychainQuery, (<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">CFTypeRef</span> *)&keyData) == <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">noErr</span>) {</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">@try</span> {</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">            ret = [<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSKeyedUnarchiver</span> <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">unarchiveObjectWithData</span>:(<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span> <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSData</span> *)keyData];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        } <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">@catch</span> (NSException *e) {</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">            </span><span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">NSLog</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">(</span>@"Unarchive of %@ failed: %@"<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">, service, e);</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        } <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">@finally</span> {</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        }</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    }</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">if</span> (keyData)</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">        <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">CFRelease</span>(keyData);</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">return</span> ret;</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">}</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;">
</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;">
</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">+ (<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">void</span>)delete:(<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span> *)service {</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSMutableDictionary</span> *keychainQuery = [<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">self</span> <span style="color:#31595d;font-variant-ligatures: no-common-ligatures;">getKeychainQuery</span>:service];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">SecItemDelete</span>((<span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">__bridge</span> <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">CFDictionaryRef</span>)keychainQuery);</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">}</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;">
</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: 'Heiti SC Light'; color: rgb(0, 132, 0);"><span style="font-family:Menlo;line-height: normal;">//</span>获得设备型号</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">+ (<span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span> *)getCurrentDeviceModel</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">{</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">int</span> mib[<span style="color:#272ad8;font-variant-ligatures: no-common-ligatures;">2</span>];</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">size_t</span> len;</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">char</span> *machine;</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    mib[<span style="color:#272ad8;font-variant-ligatures: no-common-ligatures;">0</span>] = <span style="color:#78492a;font-variant-ligatures: no-common-ligatures;">CTL_HW</span>;</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    mib[<span style="color:#272ad8;font-variant-ligatures: no-common-ligatures;">1</span>] = <span style="color:#78492a;font-variant-ligatures: no-common-ligatures;">HW_MACHINE</span>;</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">sysctl</span>(mib, <span style="color:#272ad8;font-variant-ligatures: no-common-ligatures;">2</span>, <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">NULL</span>, &len, <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">NULL</span>, <span style="color:#272ad8;font-variant-ligatures: no-common-ligatures;">0</span>);</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    machine = <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">malloc</span>(len);</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">sysctl</span>(mib, <span style="color:#272ad8;font-variant-ligatures: no-common-ligatures;">2</span>, machine, &len, <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">NULL</span>, <span style="color:#272ad8;font-variant-ligatures: no-common-ligatures;">0</span>);</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(61, 29, 129);"><span style="color:#000000;font-variant-ligatures: no-common-ligatures;">    </span><span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> *platform = [</span><span style="color:#703daa;font-variant-ligatures: no-common-ligatures;">NSString</span><span style="color:#000000;font-variant-ligatures: no-common-ligatures;"> </span>stringWithCString<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">:machine </span>encoding<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">:</span>NSUTF8StringEncoding<span style="color:#000000;font-variant-ligatures: no-common-ligatures;">];</span></p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#3d1d81;font-variant-ligatures: no-common-ligatures;">free</span>(machine);</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">    <span style="color:#bb2ca2;font-variant-ligatures: no-common-ligatures;">return</span> platform;</p><p>
</p><p style="font-size: 14px; line-height: normal; font-family: Menlo;">}</p>

iOS 获取手机 唯一标识相关推荐

  1. iOS获取设备唯一标识的各种方法?IDFA、IDFV、UDID分别是什么含义?

    http://www.ithao123.cn/content-8688001.html iOS获取设备唯一标识的各种方法?IDFA.IDFV.UDID分别是什么含义? [摘要:1.UDID (Uniq ...

  2. 通过goole获取手机唯一标识

    国内的一些方法获取手机的唯一标识现在7.0之后都不好了,不多说直接上代码,主要是根据goole商店 import android.content.ComponentName; import andro ...

  3. Android 利用阿里UTD库 获取手机唯一标识

    因为上传服务器基本上都会用到唯一标识,类似于设备id,uid等其实都可以但是有时候因为手机的原因这个唯一标识可能会为空或者会出现重复的情况,翻翻找找想着想支付宝,淘宝这样的应用是怎么获取的呢,阿里其实 ...

  4. iOS获取设备唯一标识

    前言 目前市面应用普遍采用用户体验,涉及到部分重要功能时候才提醒用户注册账户,而用户之前的操作,比如收藏,点赞,关注等内容需要同时关联进注册的账户,那么根据什么记录用户的操作信息就尤为重要.下面就列出 ...

  5. 获取手机唯一标识插件_H5能获取到手机设备ID或者手机浏览器唯一识别码吗

    content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no"> JS获取手机型 ...

  6. ionic开发——获取手机唯一标识imei码

    首先,我们要添加了cordova-plugin-device插件,具体流程可以查看ionic开发获取手机设备信息点击打开链接 这篇说明如何获取手机的imei码 我们需要在cordova-plugin- ...

  7. iOS获取手机唯一标识符来判断不同终端登录(IDFA和UUID分析)

    11.13更新 广告标示符,适用于对外:例如广告推广,换量等跨应用的用户追踪等. 是iOS 6中另外一个新的方法,提供了一个方法advertisingIdentifier,通过调用该方法会返回一个NS ...

  8. ios -获取手机唯一imei码

    相信各位也知道,苹果无法获取imei.虽然不能直接获取imei,但可以创建类似imei用途的唯一key.imei 具有唯一性.如果不是拿imei去查询手机信息的话,就可以自己创建新的key代替imei ...

  9. uniapp获取手机唯一标识IMEI、MAC、UUID

    // #ifdef APP // 导入Java类.Networklnterface类表示一个由名称和分配给此接口的IP地址列表组成的网络接口 const net = plus.android.impo ...

  10. swift获取openuuid_iOS获取设备唯一标识:UDID、IDFA、IDFV、OpenIDFA、SimulateIDFA等.

    1. UDID UDID全称是Unique Device Identifier,顾名思义,它就是苹果iOS设备的唯一标识码,它由40个字符的字母和数字组成.在很多需要限制一台设备一个张红的应用中经常会 ...

最新文章

  1. 嵌入式开发「坑」太多?MathWorks 高级工程师教你 debug
  2. oracle修改filesystem,(转):oracle、filesystem、backup日常巡检脚本
  3. php no route to host,java.net.NoRouteToHostException: No route to host解决方法
  4. html 甘特图_工具项目管理工具详解——甘特图
  5. Python一句话过滤字符串中的空白字符和中英文标点
  6. html5 游戏 算法,JS/HTML5游戏常用算法之路径搜索算法 A*寻路算法完整实例
  7. php 四级联动插件,php四级联动
  8. 上交所、深交所、中登结算的接口文档及下载链接
  9. JAVA----JSON序列化错误:InvalidDefinitionException: No serializer found for class org.apache.ibatis.execut
  10. Xbox One Dance Central Spotlight 歌曲列表
  11. 测试小兵成长记:柳暗花明又一村
  12. Git恢复已删除文件
  13. Windows下令QProcess弹出CMD界面
  14. 【教程搬运】读懂github上的工程代码——带你熟悉Python中的Parser
  15. Linux下配置DNS服务
  16. 计算机网络离不开光缆,无线网络论文.doc
  17. Lighting Window 光照设置界面 光照系列2
  18. 形式语言与自动机及其在NLP中的应用
  19. 限制输入长度,输入数字的大小和禁止输入e
  20. 语音短信的几种应用场景

热门文章

  1. OutMan——C语言中文件的操作
  2. 计算机操作系统产生的先后顺序,任务调度优先级
  3. 你以为你了解Kaggle吗?| 超级干货
  4. 人文讲座之《阳明心学与今日中国》
  5. 用计算机弹九八k的乐谱,完整版儿童歌曲简谱大全.docx
  6. 漫威宇宙影视作品及观看顺序
  7. 1024 程序员节|用代码,改变世界
  8. 2016用户体验行业调查报告
  9. 基于SONY CCD ICX285的成像电路设计
  10. 实验五:暴力破解防范措施和防范误区