title: iOS 7 fresh reset device does not send TokenUpdate to server after MDM mobileconfig profile installs
body: <p><strong>Summary</strong></p>
  
  <p>I have an iPad Mini with iOS 7.0 (11A465) installed on it. If I go to "Settings > General > Reset > Erase All Content and Settings" and erase the device, and then successfully install an MDM configuration profile on the device, during the enrollment process the device sends to the server an "Authenticate" XML payload, but afterwards it doesn't send any "TokenUpdate" payload as expected. So I have no means of sending push notifications to the device using APNS. If I remove the MDM configuration profile and reinstall it, everything works fine. And no matter how many times I remove and install the MDM configuration profile, it will always work fine. But if I erase the device again, it won't work at first attempt.</p>
  
  <p><strong>Steps to Reproduce</strong></p>
  
  <ol>
  <li>I reset the device (iPad Mini iOS 7.0 (11A465)) by going to "Settings > General > Reset > Erase All Content and Settings"</li>
  <li>After the device reinitializes, I set up a Wi-Fi connection</li>
  <li>I open up Safari and download an MDM configuration profile (OTA); the profile doesn't contain a SCEP server configuration, but instead has a PKCS12 self-signed certificate inside (I attached the MDM configuration profile; it's a file called "mdm.mobileconfig"); the profile also contains a check-in URL</li>
  <li>I successfully install the profile</li>
  <li>The device uploads an XML payload to the check-in URL, which contains these 2 nodes (amongst other nodes):
  MessageType
  Authenticate</li>
  <li>No matter how much I wait, the device doesn't upload anything else. However, I expect the device to also upload at least one more XML payload containing the following 2 nodes:
  MessageType
  TokenUpdate</li>
  <li>I manually remove the MDM configuration profile</li>
  <li>I repeat steps 3, 4 and 5</li>
  <li>This time, the device also uploads the expected XML payload containing the device token, which is perfect, because it allows me to send notifications through APNS</li>
  <li>I am now able to repeat steps 7, 8, 9 time and time again flawlessly</li>
  <li>If I start all over with step 1, the bug described at step 6 reemerges</li>
  </ol>
  
  <p><strong>Expected Results</strong></p>
  
  <p>The expected result is to ALWAYS obtain the device token after successfully installing an MDM configuration profile on my iPad Mini iOS 7.0 (11A465) device, even after the device gets reset to factory settings.</p>
  
  <p><strong>Actual Results</strong></p>
  
  <p>The first time I install an MDM configuration profile on a fresh (factory settings) device, the device doesn't upload the device token to the check-in server.</p>
  
  <p>This is the mobileconfig(not with real links or certificate)</p>
  
  <pre><code>    &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
  &lt;plist version="1.0"&gt;
  &lt;dict&gt;
      &lt;key&gt;PayloadContent&lt;/key&gt;
      &lt;array&gt;
          &lt;dict&gt;
              &lt;key&gt;AccessRights&lt;/key&gt;
              &lt;integer&gt;8191&lt;/integer&gt;
              &lt;key&gt;CheckInURL&lt;/key&gt;
              &lt;string&gt;https://checkin.url&lt;/string&gt;
              &lt;key&gt;CheckOutWhenRemoved&lt;/key&gt;
              &lt;true/&gt;
              &lt;key&gt;IdentityCertificateUUID&lt;/key&gt;
              &lt;string&gt;AAAA-AAAA-AAAAA&lt;/string&gt;
              &lt;key&gt;PayloadDescription&lt;/key&gt;
              &lt;string&gt;Remote management of iOS mobile devices&lt;/string&gt;
              &lt;key&gt;PayloadDisplayName&lt;/key&gt;
              &lt;string&gt;Mobile Device Management&lt;/string&gt;
              &lt;key&gt;PayloadIdentifier&lt;/key&gt;
              &lt;string&gt;com.mdm.identifier&lt;/string&gt;
              &lt;key&gt;PayloadOrganization&lt;/key&gt;
              &lt;string&gt;Organization&lt;/string&gt;
              &lt;key&gt;PayloadType&lt;/key&gt;
              &lt;string&gt;com.apple.mdm&lt;/string&gt;
              &lt;key&gt;PayloadUUID&lt;/key&gt;
              &lt;string&gt;aaaaa-aaaaaa-aaaaa-aaaaa&lt;/string&gt;
              &lt;key&gt;PayloadVersion&lt;/key&gt;
              &lt;integer&gt;1&lt;/integer&gt;
              &lt;key&gt;ServerURL&lt;/key&gt;
              &lt;string&gt;https://server.url&lt;/string&gt;
              &lt;key&gt;SignMessage&lt;/key&gt;
              &lt;false/&gt;
              &lt;key&gt;Topic&lt;/key&gt;
              &lt;string&gt;com.apple.topic&lt;/string&gt;
              &lt;key&gt;UseDevelopmentAPNS&lt;/key&gt;
              &lt;true/&gt;
          &lt;/dict&gt;
          &lt;dict&gt;
              &lt;key&gt;Password&lt;/key&gt;
              &lt;string&gt;password&lt;/string&gt;
              &lt;key&gt;PayloadCertificateFileName&lt;/key&gt;
              &lt;string&gt;certificate.p12&lt;/string&gt;
              &lt;key&gt;PayloadContent&lt;/key&gt;
              &lt;data&gt;
              XXXXXXXXXXXXXXXXXXXXXXXXXXX
              &lt;/data&gt;
              &lt;key&gt;PayloadDescription&lt;/key&gt;
              &lt;string&gt;Provides device authentication (certificate or identity).&lt;/string&gt;
              &lt;key&gt;PayloadDisplayName&lt;/key&gt;
              &lt;string&gt;SSL Certificate&lt;/string&gt;
              &lt;key&gt;PayloadIdentifier&lt;/key&gt;
              &lt;string&gt;com.identifier.test&lt;/string&gt;
              &lt;key&gt;PayloadOrganization&lt;/key&gt;
              &lt;string&gt;Organization&lt;/string&gt;
              &lt;key&gt;PayloadType&lt;/key&gt;
              &lt;string&gt;com.apple.security.pkcs12&lt;/string&gt;
              &lt;key&gt;PayloadUUID&lt;/key&gt;
              &lt;string&gt;AAAA-AAAA-AAAAA&lt;/string&gt;
              &lt;key&gt;PayloadVersion&lt;/key&gt;
              &lt;integer&gt;1&lt;/integer&gt;
          &lt;/dict&gt;
      &lt;/array&gt;
      &lt;key&gt;PayloadDescription&lt;/key&gt;
      &lt;string&gt;Remote management of iOS mobile devices&lt;/string&gt;
      &lt;key&gt;PayloadDisplayName&lt;/key&gt;
      &lt;string&gt;Mobile Device Management&lt;/string&gt;
      &lt;key&gt;PayloadIdentifier&lt;/key&gt;
      &lt;string&gt;com.identifier.test&lt;/string&gt;
      &lt;key&gt;PayloadOrganization&lt;/key&gt;
      &lt;string&gt;Organization&lt;/string&gt;
      &lt;key&gt;PayloadRemovalDisallowed&lt;/key&gt;
      &lt;false/&gt;
      &lt;key&gt;PayloadType&lt;/key&gt;
      &lt;string&gt;Configuration&lt;/string&gt;
      &lt;key&gt;PayloadUUID&lt;/key&gt;
      &lt;string&gt;aaa-aaaa-aaaa&lt;/string&gt;
      &lt;key&gt;PayloadVersion&lt;/key&gt;
      &lt;integer&gt;1&lt;/integer&gt;
  &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>
  
  <hr>
  
  <p>This is the log from IPCU</p>
  
  <pre><code>Oct  2 18:34:06 iPad profiled[183] &lt;Notice&gt;: (Note ) profiled: Service starting...
  Oct  2 18:34:06 iPad profiled[183] &lt;Notice&gt;: (Note ) MC: Profile “com.identifier.test” queued for installation.
  Oct  2 18:34:07 iPad Preferences[172] &lt;Warning&gt;: void unloadAPTableCellImages(): unloading images
  Oct  2 18:34:11 iPad profiled[183] &lt;Notice&gt;: (Note ) MC: Checking for MDM installation...
  Oct  2 18:34:11 iPad profiled[183] &lt;Notice&gt;: (Note ) MC: ...finished checking for MDM installation.
  Oct  2 18:34:11 iPad profiled[183] &lt;Notice&gt;: (Note ) MC: Beginning profile installation...
  Oct  2 18:34:12 iPad profiled[183] &lt;Error&gt;: MKBDeviceLockAssertion: Status missing from response
  Oct  2 18:34:12 iPad profiled[183] &lt;Error&gt;: __MKBAssertionFinalize: __MKBAssertionFinalize(0x14d58ba0)
  Oct  2 18:34:12 iPad profiled[183] &lt;Error&gt;: MKBDeviceLockAssertion: MKBDeviceLockAssertion  (asserttype:544164 with error 22)
  Oct  2 18:34:12 iPad profiled[183] &lt;Notice&gt;: (Error) MC: Could not hold keybag lock assertion. Error: The operation couldn’t be completed. Invalid argument
  Oct  2 18:34:12 iPad securityd[83] &lt;Error&gt;:  SecErrorGetOSStatus unknown error domain: com.apple.security.sos.error for error: The operation couldn’t be completed. (com.apple.security.sos.error error 2 - Public Key not available - failed to register before call)
  Oct  2 18:34:12 iPad securityd[83] &lt;Error&gt;:  securityd_xpc_dictionary_handler sbd[95] DeviceInCircle The operation couldn’t be completed. (com.apple.security.sos.error error 2 - Public Key not available - failed to register before call)
  Oct  2 18:34:12 iPad securityd[83] &lt;Error&gt;:  SecErrorGetOSStatus unknown error domain: com.apple.security.sos.error for error: The operation couldn’t be completed. (com.apple.security.sos.error error 2 - Public Key not available - failed to register before call)
  Oct  2 18:34:12 iPad securityd[83] &lt;Error&gt;:  securityd_xpc_dictionary_handler sbd[95] DeviceInCircle The operation couldn’t be completed. (com.apple.security.sos.error error 2 - Public Key not available - failed to register before call)
  Oct  2 18:34:12 iPad profiled[183] &lt;Error&gt;: TASK-ASSERT: cfurlcache - truncate DB - FAILED to get assertion, going commando!
  Oct  2 18:34:13 iPad profiled[183] &lt;Error&gt;: MKBDeviceGetGracePeriod: MKBDeviceGetGracePeriod() =&gt; (0,0,0)
  Oct  2 18:34:13 iPad profiled[183] &lt;Error&gt;: MKBDeviceGetGracePeriod: MKBDeviceGetGracePeriod() =&gt; (0,0,0)
  Oct  2 18:34:13 iPad profiled[183] &lt;Error&gt;: get_longlongvalue_for_key: failed to get GracePeriod
  Oct  2 18:34:13 iPad profiled[183] &lt;Error&gt;: get_longlongvalue_for_key: failed to get MaxLifetime
  Oct  2 18:34:13 iPad profiled[183] &lt;Error&gt;: MKBDeviceSetGracePeriod: MKBDeviceSetGracePeriod(-1,5,-1)
  Oct  2 18:34:13 iPad profiled[183] &lt;Error&gt;: MKBDeviceSetGracePeriod: MKBDeviceSetGracePeriod: from AKS 0
  Oct  2 18:34:13 iPad keybagd[44] &lt;Error&gt;: 0x297000 __update_system_keybag_block_invoke: Updating System Keybag
  Oct  2 18:34:13 iPad keybagd[44] &lt;Error&gt;: 0x297000 KBUpdateSystemKeyBag: Got opaqueStuff from ondisk keybag
  Oct  2 18:34:13 iPad keybagd[44] &lt;Error&gt;: 0x297000 KBUpdateSystemKeyBag: Saved new keybag with result 2715424
  Oct  2 18:34:13 iPad profiled[183] &lt;Notice&gt;: (Note ) MC: Profile “com.identifier.test” installed.
  Oct  2 18:34:13 iPad afcd[157] &lt;Error&gt;: Checking for changed log settings
  Oct  2 18:34:13 iPad afcd[157] &lt;Error&gt;: valid 0 value 0
  Oct  2 18:34:13 iPad afcd[157] &lt;Error&gt;: Verbose logging disabled
  Oct  2 18:34:13 iPad Preferences[172] &lt;Warning&gt;: -[VPNConnectionStore reloadVPN]: The active VPN configuration has changed from (null) to (null)
  Oct  2 18:34:13 iPad Preferences[172] &lt;Warning&gt;: -[VPNBundleController _vpnConfigurationChanged:] (0x14e89fd0:&lt;VPNBundleController: 0x14e89fd0&gt;): _serviceCount(0), serviceCount(0), toggleInRootMenu(0), RootMenuItem(1)
  Oct  2 18:34:13 iPad lockdownd[51] &lt;Error&gt;: FAILURE: Failed to open property list at file:///private/var/db/launchd.db/com.apple.launchd/overrides.plist for reading. (The operation couldn’t be completed. No such file or directory)
  Oct  2 18:34:13 iPad mc_mobile_tunnel[188] &lt;Notice&gt;: (Note ) MC: mc_mobile_tunnel starting.
  Oct  2 18:34:14 iPad corecaptured[186] &lt;Warning&gt;: CCProfileMonitor::profileCallback Entered token:1
  Oct  2 18:34:14 iPad corecaptured[186] &lt;Warning&gt;: CCLogTap::profileRemoved
  Oct  2 18:34:14 iPad corecaptured[186] &lt;Warning&gt;: CCDataFile::profileRemoved
  Oct  2 18:34:14 iPad corecaptured[186] &lt;Warning&gt;: CCLogTap::profileRemoved
  Oct  2 18:34:14 iPad corecaptured[186] &lt;Warning&gt;: CCProfileMonitor::setStreamEventHandler 
  Oct  2 18:34:14 iPad corecaptured[186] &lt;Warning&gt;: CCXPCService::setStreamEventHandler Registered for notification callback.
  Oct  2 18:34:14 iPad corecaptured[186] &lt;Warning&gt;: CCXPCService::setStreamEventHandler Woken up by notifyd.
  Oct  2 18:34:14 iPad corecaptured[186] &lt;Warning&gt;: CCProfileMonitor::profileCallback Entered token:0
  Oct  2 18:34:14 iPad corecaptured[186] &lt;Warning&gt;: CCLogTap::profileRemoved
  Oct  2 18:34:14 iPad corecaptured[186] &lt;Warning&gt;: CCDataFile::profileRemoved
  Oct  2 18:34:14 iPad corecaptured[186] &lt;Warning&gt;: CCLogTap::profileRemoved
  Oct  2 18:34:14 iPad mdmd[184] &lt;Notice&gt;: (Note ) MDM: mdmd starting...
  Oct  2 18:34:14 iPad mdmd[184] &lt;Notice&gt;: (Note ) MDM: Looking for managed app states to clean up
  Oct  2 18:34:14 iPad mdmd[184] &lt;Notice&gt;: (Note ) MDM: Waiting for push token to be assigned to this device...
  Oct  2 18:34:14 iPad mdmd[184] &lt;Notice&gt;: (Note ) MDM: Network reachability has changed.
  Oct  2 18:34:14 iPad mdmd[184] &lt;Notice&gt;: (Note ) MDM: Network reachability has changed.
  Oct  2 18:34:14 iPad securityd[83] &lt;Error&gt;:  SecErrorGetOSStatus unknown error domain: com.apple.security.sos.error for error: The operation couldn’t be completed. (com.apple.security.sos.error error 2 - Public Key not available - failed to register before call)
  Oct  2 18:34:14 iPad securityd[83] &lt;Error&gt;:  securityd_xpc_dictionary_handler sbd[95] DeviceInCircle The operation couldn’t be completed. (com.apple.security.sos.error error 2 - Public Key not available - failed to register before call)
  Oct  2 18:34:14 iPad securityd[83] &lt;Error&gt;:  SecErrorGetOSStatus unknown error domain: com.apple.security.sos.error for error: The operation couldn’t be completed. (com.apple.security.sos.error error 2 - Public Key not available - failed to register before call)
  Oct  2 18:34:14 iPad securityd[83] &lt;Error&gt;:  securityd_xpc_dictionary_handler sbd[95] DeviceInCircle The operation couldn’t be completed. (com.apple.security.sos.error error 2 - Public Key not available - failed to register before call)
  Oct  2 18:34:14 iPad awdd[185] &lt;Error&gt;: CoreLocation: CLClient is deprecated. Will be obsolete soon.
  Oct  2 18:34:22 iPad profiled[183] &lt;Error&gt;: TASK-ASSERT: cfurlcache - ProcessCacheTask - FAILED to get task-assertion, going commando with 1 items to process.
  Oct  2 18:34:23 iPad mc_mobile_tunnel[188] &lt;Notice&gt;: (Note ) MC: mc_mobile_tunnel shutting down.
  Oct  2 18:34:25 iPad mdmd[184] &lt;Notice&gt;: (Note ) MDM: Timed out waiting for push token. Continuing...
  Oct  2 18:34:25 iPad mdmd[184] &lt;Notice&gt;: (Note ) MDM: Waiting for push token to be assigned to this device...
  Oct  2 18:34:29 iPad mdmd[184] &lt;Notice&gt;: (Note ) MDM: mdmd stopping.
  Oct  2 18:34:36 iPad profiled[183] &lt;Notice&gt;: (Note ) profiled: Service stopping.
  Oct  2 18:34:44 iPad wifid[15] &lt;Error&gt;: WiFi:[402420884.811876]: Enable WoW requested by "apsd"
  Oct  2 18:34:44 iPad awdd[189] &lt;Error&gt;: CoreLocation: CLClient is deprecated. Will be obsolete soon.
  Oct  2 18:34:47 iPad securityd[83] &lt;Error&gt;:  SecErrorGetOSStatus unknown error domain: com.apple.security.sos.error for error: The operation couldn’t be completed. (com.apple.security.sos.error error 2 - Public Key not available - failed to register before call)
  Oct  2 18:34:47 iPad securityd[83] &lt;Error&gt;:  securityd_xpc_dictionary_handler sbd[95] DeviceInCircle The operation couldn’t be completed. (com.apple.security.sos.error error 2 - Public Key not available - failed to register before call)
  Oct  2 18:34:47 iPad mdmd[191] &lt;Notice&gt;: (Note ) MDM: mdmd starting...
  Oct  2 18:34:47 iPad mdmd[191] &lt;Notice&gt;: (Note ) MDM: Looking for managed app states to clean up
  Oct  2 18:34:47 iPad profiled[192] &lt;Notice&gt;: (Note ) profiled: Service starting...
  Oct  2 18:34:47 iPad mdmd[191] &lt;Notice&gt;: (Note ) MDM: Network reachability has changed.
  Oct  2 18:34:47 iPad mdmd[191] &lt;Notice&gt;: (Note ) MDM: Network reachability has changed.
  Oct  2 18:34:47 iPad mdmd[191] &lt;Notice&gt;: (Note ) MDM: Push token received.
  Oct  2 18:34:51 iPad mdmd[191] &lt;Notice&gt;: (Note ) MDM: mdmd stopping.
  Oct  2 18:34:58 iPad profiled[192] &lt;Notice&gt;: (Note ) profiled: Service stopping.
  Oct  2 18:35:39 iPad cplogd[180] &lt;Warning&gt;: Exiting.
  Oct  2 18:36:01 iPad backboardd[28] &lt;Notice&gt;: ALS: SetDisplayFactor: factor=0.0500
  Oct  2 18:36:16 iPad backboardd[28] &lt;Notice&gt;: ALS: SetDisplayFactor: factor=0.0000
  Oct  2 18:36:16 iPad kernel[0] &lt;Debug&gt;: AppleMultitouchN1SPI: updating power statistics
  Oct  2 18:36:16 iPad backboardd[28] &lt;Notice&gt;: MultitouchHID: detection mode: 3-&gt;255
  Oct  2 18:36:16 iPad kernel[0] &lt;Debug&gt;: ALS: AppleARMBacklight::setBacklightEnableGated 0 (set level to 0x36e)
  Oct  2 18:36:16 iPad backboardd[28] &lt;Notice&gt;: Posting 'com.apple.iokit.hid.displayStatus' notifyState=0
  Oct  2 18:36:16 iPad SpringBoard[33] &lt;Warning&gt;: [MPUNowPlayingController] Not registered for now playing notifications. Ignoring call to -unregisterForNotifications.
  Oct  2 18:36:16 iPad profiled[193] &lt;Notice&gt;: (Note ) profiled: Service starting...
  Oct  2 18:36:16 iPad touchsetupd[115] &lt;Warning&gt;: WPTransfer deallocing
  Oct  2 18:36:17 iPad cplogd[194] &lt;Warning&gt;: Starting.
  Oct  2 18:36:17 iPad kernel[0] &lt;Debug&gt;: ALS: AppleARMBacklight::handleMessageGated - framebufferState -&gt; 0
  </code></pre>