レスポンスを返却する処理
const rangeHeader = fetchEvent.request.headers.get('range');
const rangeMatch = rangeHeader.match(/^bytes\=(\d+)\-(\d+)?/)
const position = Number(rangeMatch[1]);
let position2 = rangeMatch[2];
if (position2) {
position2 = Number(position2);
}
if (!rangeHeader) {
cacheFirst(fetchEvent);
return;
}
fetchEvent.respondWith(
caches.open(CACHE_VERSION)
.then((cache) => {
return cache.match(fetchEvent.request.url);
})
.then((response) => {
if (!response) {
fetch(fetchEvent.request.url).then((res) => {
return res.arrayBuffer();
})
}
return response.arrayBuffer();
})
...
...
.then((arrayBuffer) => {
let responseHeaders = {
status: 206,
statusText: 'Partial Content',
headers: [
['Content-Type', 'video/mp4'],
['Content-Range', 'bytes ' + position + '-' +
(position2 || (arrayBuffer.byteLength - 1)) + '/' +
arrayBuffer.byteLength]]
};
let arrayBufferSliced = {};
if (position2 > 0) {
arrayBufferSliced = arrayBuffer.slice(position, position2 + 1);
} else {
arrayBufferSliced = arrayBuffer.slice(position);
}
return new Response(
arrayBufferSliced, responseHeaders
);
})
)
動かなかったポイントその2:iOSのスプラッシュスクリーン
- Androidは
manifest.json
に以下の項目を設定するとスプラッシュスクリーンを自動的に生成してくれるname
background_color
icons
(少なくとも512px x 512pxで.png
)
- iOSはしてくれない
;
解決方法
対象デバイスごとに端末のサイズや、画像解像度、縦向き、横向きをlink
要素のmedia
属性で設定する
<link href="/path/to/iphonex_splash.png"
media="(device-width: 375px) and (device-height: 812px)
and (-webkit-device-pixel-ratio: 3)
and (orientation: portrait)"
rel="apple-touch-startup-image">
<link href="/path/to/iphonex_splash_landscape.png"
media="(device-width: 375px) and (device-height: 812px)
and (-webkit-device-pixel-ratio: 3)
and (orientation: landscape)"
rel="apple-touch-startup-image">
- サイズはHuman Interface Guidlinesを参照
- オンラインで縦向きの画像しか生成しないがiOS Splash Screen Generatorがあったりする
- Sketch用のiOS Splash screens templateとかもあるみたい
- ※ Media Queries Level 4から
device-width
とdevice-height
が非推奨になるのでどうなるのか…width
とheight
で試したがだめでした
おまけ:iOSのステータスバー
- Androidはmanifest.jsonのステータスバーの色を
theme_color
で変更可能 - iOSはできない
解決方法
Metaタグを設定する
<meta name="apple-mobile-web-app-status-bar-style" content="black">
default
:黒文字に白背景black
:白文字に黒背景black-translucent
:白文字に透明
この件から学習したこと
-
あとからPWAを導入する際は、既存コンテンツに影響ないか充分に注意しよう
-
AndroidとiOSの実装方法の違いを把握する
-
実機でデバッグをちゃんとしよう(当たり前)