1.后台不执行
首先加载库文件: AudioToolBox.framework
引入头文件: #import “AudioToolbox/AudioToolbox.h”(温馨提示:由于是调用objective-c注意文件名)
开启方法: AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
//你不能修改震动参数,每个调用都会生成一个简短的1~2秒的震动。在不支持震动的平台上,该调用不执行任何操作,但也不会发生错误 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { // IOS 7 Support Required NSLog(@"收到通知:%@", userInfo); [APServicehandleRemoteNotification:userInfo]; completionHandler(UIBackgroundFetchResultNewData); // 收到通知后连续震动 AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate, NULL, NULL, systemAudioCallback, NULL); AudioServicesPlaySystemSound (kSystemSoundID_Vibrate); } void systemAudioCallback (SystemSoundID soundID, void* clientData) { AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); }
2.前台后台均执行
// 收到通知后连续震动 for (int i=0; i<10; i++) { [NSThread sleepForTimeInterval:0.7]; AudioServicesPlaySystemSound (kSystemSoundID_Vibrate); }
时间: 2024-10-03 22:42:18