为iPhone开发应用程序,其中包含需要通过耳机收听的音频文件.
如何检查耳机是否未插入,以便告诉用户插入耳机.
我有来自另一个线程的以下代码,但不推荐使用audioSessionGetProperty方法.任何人都知道如何更改以下代码以使其工作或拥有自己的代码/解决方案.
谢谢.
- (BOOL)isHeadsetPluggedIn {
UInt32 routeSize = sizeof (CFStringRef);
CFStringRef route;
//Maybe changing it to something like the following would work for iOS7?
//AVAudioSession* session = [AVAudioSession sharedInstance];
//OSStatus error = [session setCategory:kAudioSessionProperty_AudioRoute...?
//the line below is whats giving me the warning
OSStatus error = AudioSessionGetProperty (kAudioSessionProperty_AudioRoute,
&routeSize,
&route);
/* Known values of route:
* "Headset"
* "Headphone"
* "Speaker"
* "SpeakerAndMicrophone"
* "HeadphonesAndMicrophone"
* "HeadsetInOut"
* "ReceiverAndMicrophone"
* "Lineout"
*/
if (!error && (route != NULL)) …Run Code Online (Sandbox Code Playgroud) 在新的xcode 5中,如何在界面构建器中使用下拉菜单将故事板视图控制器连接到您的类,现在如何完成?
当我完成我的SKScene时,有没有办法从我的SKScene课程中解雇SKScene?
如果没有回到我的ViewController,我提出我的SKScene [skView presentScene:theScene];有没有办法重新启动场景或从我的SKView中删除?
该SKScene类参考和SKView类参考都没有帮助.
更新:
以下代码从我的SKView中删除了我的场景,[yourSKView presentScene:nil];但是当我回到我的视图控制器中时,场景仍然在后台运行.我总是可以在游戏结束时暂停它并将其发送回我的视图控制器(菜单),但我想知道是否还有另一种方法,然后暂停它就像完全删除它一样?
-(void)endTheGame {
[highscoreLabel removeFromSuperview];
NSLog(@"Game Over");
//would like to end here before calling the below method in my view controller
[self.delegate mySceneDidFinish:self];
}
Run Code Online (Sandbox Code Playgroud) 所以我有这个应用程序我正在努力你可以通过倾斜设备(加速度计)在屏幕上滚动球.我怎样才能改变下面的代码,这样我就不必将手机保持平衡,并将其作为我的中立平衡点.我想要的是,无论你在应用程序加载时对设备的任何倾斜,这都是神经平衡点.从当前角度来看,您握住设备即中性点.中立平衡点意味着球几乎仍然存在的点.希望这清楚我想要什么.该应用程序也只是landscapeRight.
注意下面的代码100%正常工作,就像它需要它为我的应用程序工作.我需要保持手机平放滚动球...
CGRect screenRect;
CGFloat screenHeight;
CGFloat screenWidth;
double currentMaxAccelX;
double currentMaxAccelY;
@property (strong, nonatomic) CMMotionManager *motionManager;
-(id)initWithSize:(CGSize)size {
//init several sizes used in all scene
screenRect = [[UIScreen mainScreen] bounds];
screenHeight = screenRect.size.height;
screenWidth = screenRect.size.width;
if (self = [super initWithSize:size]) {
self.motionManager = [[CMMotionManager alloc] init];
self.motionManager.accelerometerUpdateInterval = .2;
[self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
[self outputAccelertionData:accelerometerData.acceleration];
if(error)
{
NSLog(@"%@", error);
}
}];
}
return self;
}
-(void)outputAccelertionData:(CMAcceleration)acceleration{
currentMaxAccelX = 0;
currentMaxAccelY = 0;
if(fabs(acceleration.x) …Run Code Online (Sandbox Code Playgroud) 我今天早上已经提交了现有应用程序的更新.更新很小,几乎没有任何变化.Apple现已发送此电子邮件说明..
必须纠正以下问题:
无效的包结构 - 您的包中包含一个包含以下问题的包:IPA包不包含Payload目录.
我该如何解决?
我在ios7和8中都遇到了一些奇怪的行为.
有时会发生全屏显示X(POTRAIT FUllSCREEN AD - 我的应用仅限横向).你点击X,你可以回到我的菜单.
但有时广告会显示没有X(LANDSCAPE FUllSCREEN AD).如果等待DiDFinish委托,则永远不会被调用.那么我试着点击它就消失了.然后它会显示另一个带有X的广告(LANDSCAPE FUllSCREEN AD).所以我点击X.然后转到另一个广告(LANDSCAPE FUllSCREEN AD),在那里DiDFinish被调用.iOS7它只会冻结显示的第3个广告.ios8它会显示第三个广告,然后转到黑屏?有没有人处理过这样的事情?
不确定当第一个广告以纵向显示时,它是否正常工作,是否有线索?
此外,显示的多个广告都是iAd而不是rev mob和iAd组合,因为我有100%的iAd填充率.目前我只是试图让iAds全屏广告始终如一地运作
我知道委托被设置为didLoad当广告加载时调用委托这也是iPhone和iPad的问题
有没有其他人有这些问题?
使用..
[interstitial presentFromViewController:self];
Run Code Online (Sandbox Code Playgroud)
代替..
[interstitial presentInView:self.view];
Run Code Online (Sandbox Code Playgroud)
使一切正常工作presentFromViewController:..但现在已弃用

这是我用的代码......
-(void)showFullScreenAd {
//Check if already requesting ad
if (requestingAd == NO) {
//[ADInterstitialAd release];
interstitial = [[ADInterstitialAd alloc] init];
interstitial.delegate = self;
self.interstitialPresentationPolicy = ADInterstitialPresentationPolicyManual;
[self requestInterstitialAdPresentation];
NSLog(@"interstitialAdREQUEST");
requestingAd = YES;
}
}
-(void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error {
interstitial = nil;
requestingAd = NO;
NSLog(@"interstitialAd didFailWithERROR"); …Run Code Online (Sandbox Code Playgroud) 我有一个背景精灵,我想给物理身体.
background.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(screenWidth , screenHeight)];
Run Code Online (Sandbox Code Playgroud)
问题是精灵在屏幕范围内,我试图在它们到达屏幕边缘时检测到与那些精灵的碰撞.相反,它会自动检测碰撞,因为我的精灵已经在背景的物理主体内.我该怎么办?
更新:我现在回答上面的问题,我有另一个问题.它检测接触正确的方式,它与我的大小和背景的位置有关,有人可以帮助我.
//init several sizes used in all scene
screenRect = [[UIScreen mainScreen] bounds];
screenHeight = screenRect.size.height;
screenWidth = screenRect.size.width;
//set background
self.background = [SKSpriteNode spriteNodeWithImageNamed:@"GameBG3.5inchN.png"];
self.background.size = CGSizeMake(screenHeight, screenWidth);
self.background.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
//add pphysics body
self.background.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:screenRect]; // 1
self.background.physicsBody.dynamic = YES; // 2
self.background.physicsBody.categoryBitMask = screenEdge; // 3
self.background.physicsBody.contactTestBitMask = cd | floppy; // 4
self.background.physicsBody.collisionBitMask = 0; // 5
[self addChild:self.background];
Run Code Online (Sandbox Code Playgroud)
答:问题在于它初始化我的尺寸游戏是风景但价值观是肖像
我有一个显示数字的标签.用户可以使用两个按钮递增或递减该标签的值.但是,如果用户持有任一按钮,则值将更快或更快地递增或递减.例如,保持1秒快1倍,2秒快2倍,3秒快3倍,依此类推.
这是我尝试但不起作用,因为它不继续调用该方法,你不能看到你UILongGessureRecognizer在一个按钮上分配多个.我需要另一种方法.有任何想法吗?
在我的viewDidLoad中
longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(incrementTwoX)];
longerPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(incrementThreeX)];
[longPressGesture setMinimumPressDuration:1.5];
[longPressGesture setMinimumPressDuration:3];
//add long and longer press gestures to ALL buttons
[weightLeftButton addGestureRecognizer:longPressGesture];
[weightLeftButton addGestureRecognizer:longerPressGesture];
[weightRightButton addGestureRecognizer:longPressGesture];
[weightRightButton addGestureRecognizer:longerPressGesture];
-(void)incrementTwoX{
NSLog(@"Holding");// doesn't get called Im guessing because you can't assign more then one long gesture recognizer to a button
}
-(void)incrementThreeX{
NSLog(@"Holding Longer");
}
- (IBAction)weightRight:(id)sender {
if([weightLabel.text isEqual: @"Not Specified"]) weightLabel.text = 0;
double value = [weightLabel.text doubleValue] + 0.1; …Run Code Online (Sandbox Code Playgroud) 在我的主要启动线程中,我需要暂停代码并启动一个新线程并等待我收到用户输入.然后我想丢弃新的线程并返回到主线程停止的位置.但最新发生的是调用新线程,但主线程继续使用代码.如何在不干扰用户使用界面按钮的情况下处理此问题?我认为可能在我的if(moveCount == 2)语句中需要另一个nscondition?或者我的主线程需要等待来自我的其他线程的信号通知用户输入被接收.
附加注意:我也希望原始线程暂停,这样我仍然可以在界面中使用我的2个UIButton.
有关收到的问题的更多补充说明:这是我正在制作的游戏.在代码中间代码在我的主要线程中意味着我的一个方法.这个方法决定我在哪个方向移动,然后我得到一个标签差异,然后进行攻击.但有时可以进行2次攻击,因此此时用户可以通过2个按钮点击屏幕来决定要进行哪次攻击.
我也很安静地告诉我,我现在不应该暂停主线程.如果是这样,替代方案是什么?谢谢
NSCondition和NSThread
@property (strong, nonatomic) NSCondition *condition;
@property (strong, nonatomic) NSThread *aThread;
Run Code Online (Sandbox Code Playgroud)
在我的viewDidLoad中创建以下内容.
// create the NSCondition instance
self.condition = [[NSCondition alloc]init];
// create the thread
self.aThread = [[NSThread alloc] initWithTarget:self selector:@selector(threadLoop) object:nil];
Run Code Online (Sandbox Code Playgroud)
代码中间的某个地方..
if(moveCount == 2){
[self.aThread start];
}
// I need to get captureDecision from user from 2 buttons before continue.. How do I pause this thread when aThread is started. Then when capture decision is received discard aThread and start here.
NSLog(@"Capture …Run Code Online (Sandbox Code Playgroud) 我知道我可以像这样改变我的图像视图的位置
myImageView.frame = CGRectMake(99, 34, 32, 32);
Run Code Online (Sandbox Code Playgroud)
但是,如何更改x值,其余部分保留原样?我意识到这是一个简单的问题,但因为我不知道如何在搜索中找到解决方案.谢谢
嗨,我有一堆圆形SKSpriteNodes与圆形物理身体.现在,当这些球滚下路径时,我希望这些SKSpritenodes图像中的一些即使在滚动时也能保持直立.所以想想一个向上的箭头.当球开始滚动时,箭头旋转成圆形.但是对于一些球来说,即使球滚动,箭头仍然指向上方.这是最好的方法吗?
编辑
所以给出了答案,但从测试结果证明它不是正确的答案.不允许球旋转会影响它沿着路径滚动的方式.所以我想我想要的是旋转,但是图像总是向用户显示,就像它不旋转一样.谢谢.
我想在我的SKScene课程中暂停我的SKScene.我知道以下代码可以暂停场景并且游戏已经开始.
self.scene.view.paused = YES;
Run Code Online (Sandbox Code Playgroud)
但是我想暂停我的场景,因为我的场景是从我班级开始的.那么最适合这种情况的方法是什么?
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
self.paused = YES;
}
return self;
}
Run Code Online (Sandbox Code Playgroud) 我使用以下代码进行检查,但它不起作用..即使在横向拍摄的图像上也总是返回纵向
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
//dismiss imagepicker controller
[self dismissViewControllerAnimated:NO completion:nil];
fishingSpotChosenImage = [info objectForKey:UIImagePickerControllerOriginalImage];
if (fishingSpotChosenImage.imageOrientation == UIImageOrientationUp) {
NSLog(@"portrait");
} else if (fishingSpotChosenImage.imageOrientation == UIImageOrientationLeft || fishingSpotChosenImage.imageOrientation == UIImageOrientationRight) {
NSLog(@"landscape");
}
}
Run Code Online (Sandbox Code Playgroud)
我假设它不起作用,因为选择时图像实际上是纵向的,所以我如何检测图像何时具有如下图所示的黑条。
ios ×12
ios7 ×7
sprite-kit ×5
skscene ×2
binaryfiles ×1
button ×1
cgrect ×1
core-motion ×1
headphones ×1
iad ×1
interstitial ×1
ios8 ×1
ipa ×1
nscondition ×1
nsthread ×1
skspritenode ×1
skview ×1
uibutton ×1
xcode5 ×1