简体   繁体   中英

xCode loses connection to device when running app

I have been building an iOS app and have been testing it both on the simulator as well as my iPad. Everything was working perfectly until-
when i recently added the code to register for push notifications to my AppDelegate.m file. Now when I try to run the app on the device the app lingers on the splash screen for a while and then xCode comes up with the following error.

process launch failed: timed out waiting for app to launch

and here's the code i added, Just in case :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 // Override point for customization after application launch.

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
   if ([[UIApplication sharedApplication]respondsToSelector:@selector(registerUserNotificationSettings:)])
   {
      UIUserNotificationType userNTypes = (UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound);

      UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNTypes categories:nil];

        NSLog(@"sherikkum registering 8.xx...");

      [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
      [[UIApplication sharedApplication] registerForRemoteNotifications];
   }
   else
   {
      [[UIApplication sharedApplication] registerForRemoteNotificationTypes: 
      (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
#else
   [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
   (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

#endif

return YES;
}

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
  NSLog(@"My token is: %@", deviceToken);

  //I added this alert coz i couldnt view NSLogs - coz my xcode wont connect
  UIAlertView *tokenalert = [[UIAlertView alloc] initWithTitle:@"Token"
                                                     message:[NSString stringWithFormat:@"%@",deviceToken]
                                                    delegate:nil
                                           cancelButtonTitle:@"OK"
                                           otherButtonTitles:nil, nil];
  [tokenalert show];
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
   NSLog(@"Failed to get token, error: %@", error);
}

Thanks

You may be using a Distribution Certificate instead of Developer Certificate while running your app. Change it in Target => Build Settings=> Code Signing .

在此处输入图片说明

If you are using a provisioning profile created from a distribution certificate, your code will not run on a device running from xcode. You need to use a provisioning profile created from a development certificate. For further details on provisioning profiles and certificates please read Apple's Documentation.

退出模拟器,清理您的应用程序,然后再次运行。它运行正常。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM