1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > android仿支付宝收款播报 【iOS】实现类似支付宝收钱语音播报功能

android仿支付宝收款播报 【iOS】实现类似支付宝收钱语音播报功能

时间:2024-02-16 09:51:12

相关推荐

android仿支付宝收款播报 【iOS】实现类似支付宝收钱语音播报功能

需求

1、实现类似支付宝收钱时语音播报

实现思路

1、集成极光推送

2、使用tts将金额播报出来(iOS10至iOS12)

3、收到推送后,处理金额,奖金额分割转换成一个个音频文件

4、将金额以本地推送形式,自定义语音播放出来

实现步骤

1、项目配置

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

2、集成极光

Cocoapods集成极光

pod 'JCore'

pod 'JPush'

在AppDelegate里面配置

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// 初始化极光

JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];

if (@available(iOS 12.0, *)) {

entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings;

} else {

// Fallback on earlier versions

entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;

}

[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];

// Required

// init Push

// notice: 2.1.5 版本的 SDK 新增的注册方法,改成可上报 IDFA,如果没有使用 IDFA 直接传 nil

[JPUSHService setupWithOption:launchOptions appKey:@"16185342a0cf0e7ada842c78"

channel:@"0"

apsForProduction:NO

advertisingIdentifier:nil];

return YES;

}

JPUSHRegisterDelegate处理

#pragma mark - JPUSHRegisterDelegate

- (void)jpushNotificationAuthorization:(JPAuthorizationStatus)status withInfo:(NSDictionary *)info {

}

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {

NSLog(@"%@", response.notification);

//完成回调

completionHandler();

}

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {

NSLog(@"%@", notification);

}

- (void)application:(UIApplication *)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

/// 注册 DeviceToken

[JPUSHService registerDeviceToken:deviceToken];

}

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification{

}

3、NotificationService

导入音频文件(不支持网络文件)

在这里插入图片描述

NotificationService.m

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {

self.contentHandler = contentHandler;

self.bestAttemptContent = [request.content mutableCopy];

NSLog(@"接到通知 NotificationService");

NSDictionary *info = self.bestAttemptContent.userInfo;

NSLog(@"info ==> %@", info);

//step1: 推送json解析,获取推送金额

NSMutableDictionary *dict = [self.bestAttemptContent.userInfo mutableCopy] ;

BOOL playaudio = [[dict objectForKey:@"amount"] boolValue] ;

if(playaudio) {

//step2:先处理金额,得到语音文件的数组,并播放语音(本地推送 -音频)

NSString *amount = [dict objectForKey:@"amount"] ;//10000

NSArray *musicArr = [[LCAudioPlayManager sharedInstance] getMusicArrayWithNum:amount];

__weak __typeof(self) weakSelf = self;

[[LCAudioPlayManager sharedInstance] pushLocalNotificationToApp:0 withArray:musicArr completed:^{

// 播放完成后,通知系统

weakSelf.contentHandler(weakSelf.bestAttemptContent);

}];

} else {

//系统通知

self.contentHandler(self.bestAttemptContent);

}

}

4、项目运行

在这里插入图片描述

在这里插入图片描述

demo地址:/download/tianzhilan0/15045548

demo地址:/tianzhilan0/ZFBShouQian.git

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。