繁体   English   中英

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

[英]xCode loses connection to device when running app

我一直在开发一个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);
}

谢谢

您可能在运行应用程序时使用分发证书而不是开发人员证书。 Target => Build Settings => Code Signing中进行更改。

在此处输入图片说明

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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