运行应用程序时,xCode失去与设备的连接

时间:2015-01-30 05:34:24

标签: ios objective-c iphone xcode

我一直在构建iOS应用程序,并且已经在模拟器和iPad上进行了测试。一切都很顺利,直到 - 当我最近添加代码以注册推送通知到我的 AppDelegate.m 文件。现在,当我尝试在设备上运行应用程序时,应用程序会在启动画面上停留一段时间,然后xCode会出现以下错误。

  

流程启动失败:等待应用启动超时

以及我添加的代码,以防万一:

- (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);
}

由于

2 个答案:

答案 0 :(得分:3)

在运行应用时,您可能正在使用分发证书而不是开发人员证书。在目标=>中更改它构建设置=>代码签名

enter image description here

如果您使用的是从分发证书创建的配置文件,则您的代码将无法在从xcode运行的设备上运行。您需要使用从开发证书创建的配置文件。有关配置文件和证书的更多详细信息,请阅读Apple's Documentation.

答案 1 :(得分:-1)

退出你的模拟器,清理你的应用程序并再次运行它。它工作正常。