2015-12-21 103 views
2

因此,我主要用swift编写,但似乎只有在Objective-c中调用此'AudioServicesPlaySystemSoundWithVibration'的方法...开始时,代码我写了没有工作,我不知道什么改变了,但它给了我现在的错误“隐式函数声明'AudioServicesPlaySystemSoundWithVibration'在C99中无效”,而不是仅仅是一个警告。同样的警告和错误标题,但现在它是我无法编译的错误。是的,我知道我正在使用私人API,但我不打算出售该应用程序,所以我不在乎苹果是怎么想的。我只需要有自定义振动。这两个函数vibrateMutate和vibrateSection在独立的swift文件中都被调用,并且在创建我的objective-c文件时,我将'import vibrate.h'放置在Bridging Header中,这是我创建的。这里是我的代码:)函数'AudioServicesPlaySystemSoundWithVibration'的隐式声明在C99错误中无效

//vibrate.h FILE NAME 

#ifndef vibrate_h 
#define vibrate_h 
@interface Vibrate : NSObject 

+ (void)vibrateMutate; 
+ (void)vibrateSectionChange; 

@end 



#endif /* vibrate_h */ 

// vibrate.m FILE NAME 

#import <Foundation/Foundation.h> 
#import <AudioToolbox/AudioServices.h> 
#import <AudioToolbox/AudioToolbox.h> 

#import "vibrate.h" 

@implementation Vibrate 

+ (void) vibrateMutate 
{ 
NSMutableDictionary* dict = [NSMutableDictionary dictionary]; 
NSMutableArray* arr = [NSMutableArray array ]; 

[arr addObject:[NSNumber numberWithBool:YES]]; 
[arr addObject:[NSNumber numberWithInt:50]]; 

[arr addObject:[NSNumber numberWithBool:NO]]; 
[arr addObject:[NSNumber numberWithInt:10]]; 


[dict setObject:arr forKey:@"VibePattern"]; 
[dict setObject:[NSNumber numberWithDouble:.25] forKey:@"Intensity"]; 

AudioServicesPlaySystemSoundWithVibration(4095,nil,dict); //ERROR 
} 

+ (void) vibrateSectionChange 
{ 
NSMutableDictionary* dict = [NSMutableDictionary dictionary]; 
NSMutableArray* arr = [NSMutableArray array ]; 

[arr addObject:[NSNumber numberWithBool:YES]]; 
[arr addObject:[NSNumber numberWithInt:150]]; 

[arr addObject:[NSNumber numberWithBool:NO]]; 
[arr addObject:[NSNumber numberWithInt:10]]; 


[dict setObject:arr forKey:@"VibePattern"]; 
[dict setObject:[NSNumber numberWithDouble:.75] forKey:@"Intensity"]; 

AudioServicesPlaySystemSoundWithVibration(4095,nil,dict); 
} 

@end 

回答

2

如果你知道调用是正确的,只是想满足编译器,你可以在你的代码中给出一个明确的定义。我不知道私有函数的正确定义是什么,但如果你不关心精确性,下面的内容应该可以工作。

void AudioServicesPlaySystemSoundWithVibration(int, id, id); 

@implementation Vibrate 
// ... 
1

只是为了记录由@PhilipMills一些额外的价值增加了​​漂亮的答案,苹果商店绝不会接受它引用任何苹果公司的非公开符号或私有API的二进制文件。

非公开API的使用:在贾斯汀移动

  • 该应用程序引用非公共符号:_AudioServicesPlaySystemSoundWithVibration

如果方法,他们用下面的消息会自动拒绝该二进制源代码中的名称与上面列出的私有Apple API 匹配,更改您的方法名称将有助于防止此应用 被标记d在未来提交。另外,请注意,一个 或以上的API可能位于应用程序附带的 静态库中。如果是这样,他们必须被删除。

+1

感谢您的意见,是的,我们知道我们无法提交到App Store,但这是一个个人项目,所以我们并不太担心。 :) –

+0

不用担心,我知道你在你的问题中提到过,但总是有分心的人不知道其含义,也许这可以节省一些时间给他们;-) – GoRoS

相关问题