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

标签 ios objective-c iphone xcode

我一直在构建一个 iOS 应用程序,并在模拟器和我的 iPad 上对其进行了测试。一切都在完美地工作,直到-
当我最近将代码添加到我的 AppDelegate.m 文件中以注册推送通知时。现在,当我尝试在设备上运行该应用程序时,该应用程序会在初始屏幕上停留一段时间,然后 xCode 出现以下错误。

process launch failed: timed out waiting for app to launch

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

- (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 中更改它。

enter image description here

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

关于ios - xCode 在运行应用程序时失去与设备的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28229824/

相关文章:

ios - "No unexpired provisioning profiles found that contain any of the keychain' s 签名证书”恐怖

objective-c - 无法从 NSTask 的标准输出获取中间输出?

ios - 在 xcode 上隐藏标签栏项目

iphone - 自定义 UITableViewCell 不会在 setNeedsDisplay 上重绘

iphone - 核心图形透明覆盖

iphone - 如何在 objective-c 中打印出bool

ios - 在 iOS 7 中打开短信收件箱

ios - PFUser.current()?.saveInBackground 错误与 UIImage()

asp.net - 无法使用 AFNetworking 将 iOS 连接到 asp.net web 服务

iphone - 无法更新 uitableview 行