質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
React Native

React Nativeは、ネイティブモバイルアプリ(iOS/Android)を作成できるJavaScriptフレームワークです。Reactと同じ設計のため、宣言的なコンポーネントでリッチなUIを開発することが可能です。

Q&A

解決済

1回答

879閲覧

expoのNotificationRequestInputの引数の設定がわからない【TransformError SyntaxError】

ok09

総合スコア11

React Native

React Nativeは、ネイティブモバイルアプリ(iOS/Android)を作成できるJavaScriptフレームワークです。Reactと同じ設計のため、宣言的なコンポーネントでリッチなUIを開発することが可能です。

0グッド

0クリップ

投稿2020/10/01 00:28

Expoで通知アプリを作っています。
triggerで毎週木曜日9時3分に通知をする設定を作ったのですが、以下のエラーが表示されました。

TransformErrorSyntaxError: /Users/user/Development/GomiApp/screens/HomeScreen.js: Unexpected token, expected ";" (16:44)

実現したいこと

scheduleNotificationの引数として、NotificationRequestInputを使うべきというアドバイスを受けたので、挿入したのですが、引数の挿入方法がDocumentに書かれておらず、調べてもわかりませんでした。
ご教示いただけると嬉しいです。

以下、現在の引数の書き方です。

React

1export interface NotificationRequestInput { 2 identifier: string; 3 content: NotificationContentInput; 4 trigger: NotificationTriggerInput; 5} 6 7Notifications.scheduleNotificationAsync();


以下、HomeScreen全文です。

React

1import { StatusBar } from 'expo-status-bar'; 2import React from 'react'; 3import GomiList from "../components/GomiList"; 4import { StyleSheet, Text, View } from 'react-native'; 5 6import * as Notifications from 'expo-notifications'; 7 8Notifications.setNotificationHandler({ 9 handleNotification: async () => ({ 10 shouldShowAlert: true, 11 shouldPlaySound: false, 12 shouldSetBadge: false, 13 }), 14}); 15 16export interface NotificationContentInput { 17 title: 'ゴミ出しの時間です!'; 18}; 19 20export interface NotificationTriggerInput { 21 type: 'calendar'; 22 repeats: true; 23 dateComponents: { 24 hour: 9; 25 minute: 3; 26 weekday: 4; 27 calendar: Calendar.current; 28 }, 29}; 30 31export interface NotificationRequestInput { 32 identifier: string; 33 content: NotificationContentInput; 34 trigger: NotificationTriggerInput; 35} 36 37Notifications.scheduleNotificationAsync(); 38 39export default function HomeScreen() { 40 return ( 41 <View style={styles.container}> 42 <View style={styles.GomiList}> 43 <GomiList title="燃えるごみ"/> 44 </View> 45 <View style={styles.GomiList}> 46 <GomiList title="燃えないごみ"/> 47 </View> 48 </View> 49 ); 50} 51 52const styles = StyleSheet.create({ 53 container: { 54 flex: 1, 55 backgroundColor: '#fff', 56 }, 57 GomiList: { 58 paddingTop: 20, 59 alignItems: 'center', 60 }, 61}); 62

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

実行したいのは下記のような処理でしょうか?

javascript

1Notifications.scheduleNotificationAsync({ 2 content: { 3 title: 'ゴミ出しの時間です!', 4 }, 5 trigger : { 6 repeats : true, 7 hour: 9, 8 minute: 3, 9 weekday: 4, 10 } 11});

だとすれば下記のようにすれば動くと思いますが、
そもそもこのソースはTypescriptでしょうか?(interfaceの記述が出ているため)

javascript

1//export interface NotificationContentInput { 2// title: 'ゴミ出しの時間です!'; 3//}; 4const content = { 5 title: 'ゴミ出しの時間です!', 6} 7 8//export interface NotificationTriggerInput { 9// type: 'calendar'; 10// repeats: true; 11// dateComponents: { 12// hour: 9; 13// minute: 3; 14// weekday: 4; 15// calendar: Calendar.current; 16// }, 17//}; 18const trigger = { 19 repeats : true, 20 hour: 9, 21 minute: 3, 22 weekday: 4, 23} 24 25//export interface NotificationRequestInput { 26// identifier: string; 27// content: NotificationContentInput; 28// trigger: NotificationTriggerInput; 29//} 30 31Notifications.scheduleNotificationAsync({ 32 content : content, 33 trigger : trigger, 34});

投稿2020/10/01 08:00

nekoniki

総合スコア2409

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ok09

2020/10/05 23:21 編集

お返事遅れてすみません! ありがとうございます! typescriptではないと思います。いまいち見分け方がわかりませんが、expoをライブラリに作るときに、 expo init とだけターミナルに入力しました。expo init typescript-projectとはしていません。 documentを参考に使っただけで、ご提示いただいたソースを用いたら正常に動きました。 本当にありがとうございます!!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問