简体   繁体   中英

Implicit Declaration of Function 'AudioServicesPlaySystemSoundWithVibration' is invalid in C99 error

So, I mainly write in swift, but it seems that the only way to call this 'AudioServicesPlaySystemSoundWithVibration' is in Objective-c... At the beginning, The code I wrote did work, I am not sure what changed but it gives me the error "Implicit Declaration of Function 'AudioServicesPlaySystemSoundWithVibration' is invalid in C99" now instead of just a warning. Same warning and error title, but now that it is an error I can't compile. Yes, I know that I am using a private API, but I do not plan to sell the app so I don't care what apple thinks. I just need to have custom vibrates. The two functions vibrateMutate and vibrateSection are both called in separate swift files, and I put the 'import vibrate.h' in the Bridging Header that I was coxed to create when I made my objective-c files. Here is my code :)

//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

If you know the call is right and just want to satisfy the compiler, you can give an explicit definition in your code. I don't know what the correct definition of the private function is but the following should work if you don't care about being precise.

void AudioServicesPlaySystemSoundWithVibration(int, id, id);

@implementation Vibrate
// ...

Just for the record to add some extra value to the nice answer by @PhilipMills, Apple Store will never accept any binary which references any Apple's non-public symbols or private APIs. They reject the binary automatically with the following message:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM