Xcode 提示问题..Thexcode 7.0 simulatorr can't be launched because it is already in use.

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.
I added an AdBannerView in a Storyboard but if I run the app I get an error:
The operation couldn’t be completed. Banner view is visible but does not have content
the whole error:
[AppDeveloper] ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=5 "The operation couldn’t be completed. Banner view is visible but does not have content" UserInfo=0x7fd86afdf330 {ADInternalErrorCode=5, NSLocalizedFailureReason=Banner view is visible but does not have content, ADInternalErrorDomain=ADErrorDomain}
Did you make sure to include ADBannerViewDelegate in your Swift file? And after that it seems the error is saying that you have not implemented
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!)
After that make sure to connect your banner view's delegate to the class your view is so that it can handle the error using the above function.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled今天使用模拟器,测试时,突然间, 模拟器起不来了。前几次必须重启机子,后来实在受不了了,就搜罗下大神们的解答!提示信息:&The Simulator can't be launched because it is already in use .&&大概意思是:  在用simulator&run 项目A的时候有时会提示,一般是另外一个项目B用着simulator,然后你command+Q退simulator,  但有时会导致项目B直接崩溃并 且使项目处于‘调试’状态。  这个时候在项目B菜单Product中stop项目,其它项目即可使用simulator了。  &但是,当时我起了一个项目。 并没有开其他项目。&查了下,解决方法,如下:  1、退出模拟器;  2、强制退出XCODE;(关键是这一步)  3、重启XCODE;&尝试一下,可以使用了。 &&记录下,继续工作...
无相关信息Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.
As the question states, I would mainly like to know whether or not my code is running in the simulator, but would also be interested in knowing the specific iphone version that is running or being simulated.
EDIT: I added the word 'programmatically' to the question name. The point of my question is to be able to dynamically include / exclude code depending on which version / simulator is running, so I'd really be looking for something like a pre-processor directive that can provide me this info.
5,28683342
2,19851924
Already asked, but with a very different title.
I'll repeat my answer from there:
It's in the SDK docs under "Compiling source code conditionally"
he relevant definitions are TARGET_OS_IPHONE and TARGET_IPHONE_SIMULATOR, which are defined in /usr/include/TargetConditionals.h within the iOS framework. On earlier versions of the toolchain, you had to write:
#include "TargetConditionals.h"
but this is no longer necessary on the current (xCode 6/iOS8) toolchain.
So, for example, if you want to check that you are running on device, you should do
#if !(TARGET_IPHONE_SIMULATOR)
if (TARGET_IPHONE_SIMULATOR)
depending on which is appropriate for your use-case.
18.3k105164
This code will tell you if you are running in a simulator.
#ifdef __i386__
NSLog(@"Running in the simulator");
NSLog(@"Running on a device");
That could be problematic based on if some things on the platform change.
This is also purported to work officially.
#if TARGET_IPHONE_SIMULATOR
NSString *hello = @"Hello, iPhone simulator!";
#elif TARGET_OS_IPHONE
NSString *hello = @"Hello, device!";
NSString *hello = @"Hello, unknown target!";
2,63111622
Not pre-processor directive, but this was what I was looking for when i c
NSString *model = [[UIDevice currentDevice] model];
if ([model isEqualToString:@"iPhone Simulator"]) {
//device is simulator
17.7k55168
The best way to do this is:
#if TARGET_IPHONE_SIMULATOR
#ifdef TARGET_IPHONE_SIMULATOR
since its always defined: 0 or 1
3,930105079
I had the same problem, both TARGET_IPHONE_SIMULATOR and TARGET_OS_IPHONE are always defined, and are set to 1. Pete's solution works, of course, but if you ever happen to build on something other than intel (unlikely, but who knows), here's something that's safe as long as the iphone hardware doesn't change (so your code will always work for the iphones currently out there):
#if defined __arm__ || defined __thumb__
#undef TARGET_IPHONE_SIMULATOR
#define TARGET_OS_IPHONE
#define TARGET_IPHONE_SIMULATOR 1
#undef TARGET_OS_IPHONE
Put that somewhere convenient, and then pretend that the TARGET_* constants were defined correctly.
The previous answers are a little dated. I found that all you need to do is query the TARGET_IPHONE_SIMULATOR macro (no need to include any other header files [assuming you are coding for iOS]).
I attempted TARGET_OS_IPHONE but it returned the same value (1) when running on an actual device and simulator, that's why I recommend using TARGET_IPHONE_SIMULATOR instead.
4,71753691
All those answer are good, but it somehow confuses newbie like me as it does not clarify compile check and runtime check. Preprocessor are before compile time, but we should make it clearer
This blog article shows
First of all, let’s shortly discuss. UIDevice provides you already information about the device
[[UIDevice currentDevice] model]
will return you “iPhone Simulator” or “iPhone” according to where the app is running.
Compile time
However what you want is to use compile time defines. Why? Because you compile your app strictly to be run either inside the Simulator or on the device. Apple makes a define called
TARGET_IPHONE_SIMULATOR. So let’s look at the code :
#if TARGET_IPHONE_SIMULATOR
NSLog(@"Running in Simulator - no app store or giro");
6,77654988
To include all types of "simulators"
NSString *model = [[UIDevice currentDevice] model];
if([model rangeOfString:@"Simulator" options:NSCaseInsensitiveSearch].location !=NSNotFound)
// we are running in a simulator
In my opinion, the answer (presented above and repeated below):
NSString *model = [[UIDevice currentDevice] model];
if ([model isEqualToString:@"iPhone Simulator"]) {
//device is simulator
is the best answer because it is obviously executed at RUNTIME versus being a COMPILE DIRECTIVE.
1,36111633
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledStack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.
I want to run tests in Xcode 4 using OCUnit without launching the simulator. Please, don't try and convince me I am doing unit testing wrong or anything like that. I like to do TDD the traditional way: write the API for the class in the tests, then make the class pass the tests. I will write separate tests that are end-to-end that run in the simulator.
If there's no way to do this, then please can someone tell me how to have the test harness not instantiate the whole app? My app is event driven, and it sends a bunch of events through when it starts up that mess with my tests.
11.1k33970
Please can someone tell me how to have the test harness not instantiate the whole app? My app is event driven, and it sends a bunch of events through when it starts up that mess with my tests.
I use Xcode 4's built-in testing. App instantiation may seem like a pain, but as I write on , it makes it possible to write tests without distinguishing between logic tests and application tests. Specifically, it lets me write unit tests for view controllers.
Here's what I do to avoid my full startup sequence:
Edit the scheme
Select the Test action
In "Test" select the Arguments tab
Disable "Use the Run action's options"
Add an environment variable, setting runningTests to YES
Edit your app delegate
Add the following to -application:didFinishLaunchingWithOptions: as soon as it makes sense to:
if (getenv("runningTests"))
return YES;
Do the same for -applicationDidBecomeActive: but simply return.
Update: I have changed my approach. See .
11.7k13159
In the last xcode version (5.0.2) you can do this in very easy way. Choose your Test target, "General" tab. Set "None" in field "Target". Then tap on "Build phases" tab and remove your Main target from "Target dependencies".
3,43121930
In your situation, I am assuming that you have a separate Logic Tests and Application Tests target (if not - you need to).
In your schemes configuration you define which targets are built for the 'Test' scheme.
If your application tests are not running, the simulator will not launch.
I suspect that you might be trying to run 'logic tests' in an 'Application tests' target (such as the one created by default by Xcode).
See more about this difference
(and how to set ut up).
5,85212251
It was pointed out in an earlier answer that logic tests are the right thing to do for this scenario. I had very tough time in getting the logic tests working with XCode Version 4.3.2 (4E2002). Looking at
helped me to understand how to do this with a clear separation. In that example, logic tests test files from the library target, not the application target. The model was encapsulated into a library which was then linked with the main target and logic tests target. The application target contained only views and controllers.
Based on this model, this is what I did to get my logic tests work correctly. Create a new target (Cocoa Touch Static Library) and move all files to be logic tested (typically all your models) to this new target. Under "Build Phases" settings add this new library in "Link Binary With Libraries" of your application target and logic tests target.
I can imagine that these instructions are little confusing. If you dissect the sample project that is mentioned above you will get a better idea.
Note, untested on Xcode 5.
I used @jon-reid’s answer, but found that Xcode adds environment-variables to the xcuserstated part of XcodeProjects, and these are user specific and not typically committed to the repository. Thus I swizzle my AppDelegate to override its loading:
@implementation MyAppDelegate (Testing)
+ (void)initialize {
SEL new = @selector(application:didFinishLaunchingWithOptions:);
SEL orig = @selector(swizzled_application:didFinishLaunchingWithOptions:);
Class c = [self class];
Method origMethod = class_getInstanceMethod(c, orig);
Method newMethod = class_getInstanceMethod(c, new);
if (class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) {
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
method_exchangeImplementations(origMethod, newMethod);
- (BOOL)swizzled_application:(id)app didFinishLaunchingWithOptions:(id)opts {
return YES;
Note, that the following is simpler and still works, though I'm not sure it is reliable:
@implementation MyAppDelegate (Testing)
- (BOOL)application:(id)app didFinishLaunchingWithOptions:(id)opts {
return YES;
This works because categories of methods in dynamically loaded components (like the testing bundle) take precedence. Swizzling feels safer though.
9,54955070
to create osx/ios compatible test suites. there are a few issues, but i found it was more reliable/compatible/straightforward than OCUnit.
GHUnit provides basic template projects for OS X and iOS, which makes initial setup simple.
Note: I generally just use my own kit for most of my testing.
11.1k33970
83.1k10122173
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled}

我要回帖

更多关于 xcode simulator 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信