宋明

  • 2024
  • 2023
  • 2022

2024 年发布 107 篇

2023 年发布 25 篇

2022 年发布 25 篇

IOS 跳转App Store进行评分

1.前言

遭遇4.2.2把我逼得没办法了,啥功能都怼上去了

2.实现

在 viewdidload 或者 viewwillappear 中判断是否需要显示评分,因为SKStoreReviewController 一年最多三次,所以我就无耻点相隔四个月调用一次

IOS 针对txt文档进行解码

如我上一篇文章记录,我加了打开其他APPtxt文件的小功能,紧接着碰到新问题了,我在测试过程中发现用户上传的TXT编码格式很多不单单是utf-8和gb2312,针对TXT文档进行解码,我一共经历过两个阶段,如下

##1.通过循环 解码不为空就返回字符串

IOS基于AVFoundation实现朗读文字

##1.心理建设

众所周知AVFoundation的朗读是个智障语气,所以想不花钱就只能忍着。

##2.speechManager

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@import AVFoundation;

@protocol TJSpeechManagerDelegate <NSObject>
@optional
- (void)didStartSpeechUtterance:(AVSpeechUtterance*)utterance;
- (void)didFinishSpeechUtterance:(AVSpeechUtterance*)utterance;
- (void)didPauseSpeechUtterance:(AVSpeechUtterance*)utterance;
- (void)didCancelSpeechUtterance:(AVSpeechUtterance*)utterance;
- (void)willSpeakRangeOfSpeechString:(NSRange)characterRange utterance:(AVSpeechUtterance *)utterance;

- (void)needRepeatSpeech:(AVSpeechUtterance *)utterance;
@end

@interface TJSpeechManager : NSObject <AVSpeechSynthesizerDelegate>


@property (nonatomic, strong) AVSpeechSynthesizer *avSpeech;
@property (nonatomic, strong) AVSpeechUtterance *speechUtt;

@property (nonatomic, assign) id <TJSpeechManagerDelegate> delegate;


- (void)setSpeechContent:(NSString *)content;


- (void)pauseSpeech;


- (void)beginSpeech;

- (void)continueSpeech;

- (void)endSpeech;

@end


#import "TJSpeechManager.h"

@implementation TJSpeechManager

- (void)setSpeechContent:(NSString *)content {
    AVSpeechUtterance *speechUtt = [AVSpeechUtterance speechUtteranceWithString:content];
    speechUtt.rate = 0.5;
    speechUtt.pitchMultiplier = 1;
            
    //设置音量,[0-1] 默认 = 1
    speechUtt.volume = 1;

    //读一段前的停顿时间
    speechUtt.preUtteranceDelay = 1;
    //读完一段后的停顿时间
    speechUtt.postUtteranceDelay = 1;
    AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
    speechUtt.voice = voice;
    self.speechUtt = speechUtt;
}

- (void)beginSpeech {
    //这里需要注意一下,一个avspeech对象只能播放一次,同一个对象中途不能重新播放。
    AVSpeechSynthesizer *avSpeech = [[AVSpeechSynthesizer alloc] init];
    avSpeech.delegate = self;
    [avSpeech speakUtterance:self.speechUtt];
    self.avSpeech = avSpeech;
}

- (void)pauseSpeech {
    [self.avSpeech pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
}

- (void)continueSpeech {
    if(self.avSpeech.isPaused) {
        [self.avSpeech continueSpeaking];
        [NSThread sleepForTimeInterval:0.25f];
    }
}

- (void)endSpeech {
    if(self.avSpeech.isSpeaking) {
        [self.avSpeech stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
        [NSThread sleepForTimeInterval:0.25f];
    }
}

//代理主要是返回给controller,用来和UI交互
#pragma mark - AVSpeechSynthesizerDelegate;
- (void)speechSynthesizer:(AVSpeechSynthesizer*)synthesizer didStartSpeechUtterance:(AVSpeechUtterance*)utterance{
    NSLog(@"---开始播放");
    if(self.delegate && [self.delegate respondsToSelector:@selector(didStartSpeechUtterance:)]) {
        [self.delegate didStartSpeechUtterance:utterance];
    }
}

- (void)speechSynthesizer:(AVSpeechSynthesizer*)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance*)utterance{
    NSLog(@"---完成播放");
    if(self.delegate && [self.delegate respondsToSelector:@selector(didFinishSpeechUtterance:)]) {
        [self.delegate didFinishSpeechUtterance:utterance];
    }
}

- (void)speechSynthesizer:(AVSpeechSynthesizer*)synthesizer didPauseSpeechUtterance:(AVSpeechUtterance*)utterance{
    NSLog(@"---播放中止");
    if(self.delegate && [self.delegate respondsToSelector:@selector(didPauseSpeechUtterance:)]) {
        [self.delegate didPauseSpeechUtterance:utterance];
    }
}

- (void)speechSynthesizer:(AVSpeechSynthesizer*)synthesizer didContinueSpeechUtterance:(AVSpeechUtterance*)utterance{
    NSLog(@"---恢复播放");
    
}

- (void)speechSynthesizer:(AVSpeechSynthesizer*)synthesizer didCancelSpeechUtterance:(AVSpeechUtterance*)utterance{
    NSLog(@"---播放取消");
    if(self.delegate && [self.delegate respondsToSelector:@selector(didCancelSpeechUtterance:)]) {
        [self.delegate didCancelSpeechUtterance:utterance];
    }
}

- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer willSpeakRangeOfSpeechString:(NSRange)characterRange utterance:(AVSpeechUtterance *)utterance {
    if(self.delegate && [self.delegate respondsToSelector:@selector(willSpeakRangeOfSpeechString:utterance:)]) {
        [self.delegate willSpeakRangeOfSpeechString:characterRange utterance:utterance];
    }
}

@end

##3.使用范例

Ios解析txt电子书

昨天上线新版本因为Other-Other账号审核被拒了,估计要等待几天了,正好抽时间把最近写的东西整理一下。

附上APP地址: 一阅阅读有想看小说的小伙伴可以试下 支持换源 支持自定义书源

IOS利用多线程进行网络请求

1.前言

这两天忙着对付Other-Other的问题,今天才抽空给APP新增了一个离线缓存的功能,由于我的APP是对书源进行转码格式化阅读,所以缓存这里是个很头疼的问题,稍不慎就会503.目前的方案就是动态切换UA和利用多线程 一章一章下 收到失败就等待一会再继续,目前测试没什么问题。

Runloop实际使用

前言

Runloop在iOS中是一个很重要的组成部分,对于任何单线程的UI模型都必须使用EvenLoop才可以连续处理不同的事件,而RunLoop就是EvenLoop模型在iOS中的实现。在前面的几篇文章中,我已经介绍了Runloop的底层原理等,这篇文章主要是从实际开发的角度,探讨一下实际上在哪些场景下,我们可以去使用RunLoop