ios极光推送离线自定义提示音

首先我们要集成极光的SDK;

下一步就要修改提示音的格式为.caf,比如default.caf然后导入工程中,并且在如图文件加入

ios极光推送离线自定义提示音_第1张图片

后台推送的消息体里面一定要设置sound的value为default.caf,也就是和你拖入工程中的文件名一致

以下代码一定要放入接收推送的方法中


#pragma mark - ios6以下接收推送消息

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {

[JPUSHService handleRemoteNotification:userInfo];

NSLog(@"iOS6及以下系统,收到通知:%@", [selflogDic:userInfo]);

}


#pragma mark - ios7以上接收推送消息

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler {

NSString*sound = [[userInfoobjectForKey:@"aps"]objectForKey:@"sound"];//播放的声音

[self loadMusic:sound];

}


#pragma mark -播放音乐

//初始化音乐播放器

- (void)loadMusic:(NSString*)strMusic

{

         drewSound= [selfloadSound:strMusic];

         AudioServicesPlaySystemSound(drewSound);

}

//加载音效

- (SystemSoundID)loadSound:(NSString*)soundFileName

{

//// 1.需要指定声音的文件路径,这个方法需要加载不同的音效

NSString*path = [[NSBundle mainBundle]pathForResource:soundFileName ofType:nil];

// 2.将路径字符串转换成url

NSURL*url = [NSURLfileURLWithPath:path];

// 3.初始化音效

// 3.1 url => CFURLRef

// 3.2 SystemSoundID

SystemSoundIDsoundId;

// url先写个错的,然后让xcode帮我们智能修订,这里的方法不要硬记!

AudioServicesCreateSystemSoundID((__bridgeCFURLRef)(url), &soundId);

//AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

returnsoundId;

}

这样你就可以试试了!

你可能感兴趣的:(ios极光推送离线自定义提示音)