[英]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.