函数的隐式声明 'AudioServicesPlaySystemSoundWithVibration' 在 C99 错误中无效
Implicit Declaration of Function 'AudioServicesPlaySystemSoundWithVibration' is invalid in C99 error
所以,我主要写在swift,但是好像只能在'AudioServicesPlaySystemSoundWithVibration'中调用这个'AudioServicesPlaySystemSoundWithVibration'...一开始,我写的代码确实有效,我不确定发生了什么变化,但它现在给了我错误 "Implicit Declaration of Function 'AudioServicesPlaySystemSoundWithVibration' is invalid in C99" 而不仅仅是警告。相同的警告和错误标题,但现在这是一个我无法编译的错误。是的,我知道我使用的是私人 API,但我不打算出售该应用程序,所以我不在乎 apple 的想法。我只需要自定义振动。这两个函数 vibrateMutate 和 vibrateSection 都在单独的 swift 文件中调用,我将 'import vibrate.h' 放在桥接 Header 中,这是我在创建 objective-c 时被迫创建的文件。这是我的代码:)
//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
如果你知道调用是对的,只是想让编译器满意,你可以在你的代码中给出明确的定义。我不知道私有函数的正确定义是什么,但如果您不关心精确性,以下内容应该可以使用。
void AudioServicesPlaySystemSoundWithVibration(int, id, id);
@implementation Vibrate
// ...
只是为了给@PhilipMills 的漂亮回答增加一些额外的价值,Apple Store 绝不会接受任何引用任何 Apple 的非 public 符号或私有 API 的二进制文件。他们使用以下消息自动拒绝二进制文件:
Non-public API usage:
- The app references non-public symbols in JustIN Mobile: _AudioServicesPlaySystemSoundWithVibration
If method names in your source code match the private Apple APIs
listed above, altering your method names will help prevent this app
from being flagged in future submissions. In addition, note that one
or more of the above APIs may be located in a static library that was
included with your app. If so, they must be removed.
所以,我主要写在swift,但是好像只能在'AudioServicesPlaySystemSoundWithVibration'中调用这个'AudioServicesPlaySystemSoundWithVibration'...一开始,我写的代码确实有效,我不确定发生了什么变化,但它现在给了我错误 "Implicit Declaration of Function 'AudioServicesPlaySystemSoundWithVibration' is invalid in C99" 而不仅仅是警告。相同的警告和错误标题,但现在这是一个我无法编译的错误。是的,我知道我使用的是私人 API,但我不打算出售该应用程序,所以我不在乎 apple 的想法。我只需要自定义振动。这两个函数 vibrateMutate 和 vibrateSection 都在单独的 swift 文件中调用,我将 'import vibrate.h' 放在桥接 Header 中,这是我在创建 objective-c 时被迫创建的文件。这是我的代码:)
//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
如果你知道调用是对的,只是想让编译器满意,你可以在你的代码中给出明确的定义。我不知道私有函数的正确定义是什么,但如果您不关心精确性,以下内容应该可以使用。
void AudioServicesPlaySystemSoundWithVibration(int, id, id);
@implementation Vibrate
// ...
只是为了给@PhilipMills 的漂亮回答增加一些额外的价值,Apple Store 绝不会接受任何引用任何 Apple 的非 public 符号或私有 API 的二进制文件。他们使用以下消息自动拒绝二进制文件:
Non-public API usage:
- The app references non-public symbols in JustIN Mobile: _AudioServicesPlaySystemSoundWithVibration
If method names in your source code match the private Apple APIs listed above, altering your method names will help prevent this app from being flagged in future submissions. In addition, note that one or more of the above APIs may be located in a static library that was included with your app. If so, they must be removed.