Skip to content

Commit

Permalink
🐛 - Fixed launch crash for unsupported Live Activities iOS versions (#…
Browse files Browse the repository at this point in the history
…255)

Co-authored-by: Guy Tepper <[email protected]>
  • Loading branch information
planecore and guytepper authored Jun 13, 2023
1 parent a36c77f commit d6c134b
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 27 deletions.
6 changes: 3 additions & 3 deletions app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import "./i18n"
import "./utils/ignore-warnings"
import React, { useState, useEffect, useRef } from "react"
import { Platform, AppState } from "react-native"
import { AppState } from "react-native"
import { QueryClient, QueryClientProvider } from "react-query"
import { NavigationContainerRef } from "@react-navigation/native"
import { SafeAreaProvider, initialWindowMetrics } from "react-native-safe-area-context"
Expand Down Expand Up @@ -47,7 +47,7 @@ if (__DEV__) {
// stack navigation, use `createNativeStackNavigator` in place of `createStackNavigator`:
// https://github.com/kmagiera/react-native-screens#using-native-stack-navigator
import { enableScreens } from "react-native-screens"
import { monitorLiveActivities } from "./utils/ios-helpers"
import { canRunLiveActivities, monitorLiveActivities } from "./utils/ios-helpers"
import { useDeepLinking } from "./hooks/use-deep-linking"
enableScreens()

Expand All @@ -67,7 +67,7 @@ function App() {

useEffect(() => {
// Activate live activities listener on iOS 16.2+
if (Platform.OS == "ios" && parseFloat(Platform.Version) >= 16.2) {
if (canRunLiveActivities) {
monitorLiveActivities()
}
}, [])
Expand Down
11 changes: 7 additions & 4 deletions app/models/ride/ride.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Instance, SnapshotOut, types } from "mobx-state-tree"
import { omit } from "ramda"
import { Platform } from "react-native"
import iOSHelpers, { ActivityAuthorizationInfo } from "../../utils/ios-helpers"
import iOSHelpers, { ActivityAuthorizationInfo, canRunLiveActivities } from "../../utils/ios-helpers"
import { trainRouteSchema } from "../train-routes/train-routes"
import { RouteItem } from "../../services/api"

Expand Down Expand Up @@ -63,7 +63,7 @@ export const RideModel = types
self.activityAuthorizationInfo = newInfo
},
async checkActivityAuthorizationInfo() {
if (Platform.OS === "ios") {
if (canRunLiveActivities) {
const info = await iOSHelpers.activityAuthorizationInfo()
this.setActivityAuthorizationInfo(info)
}
Expand All @@ -77,8 +77,9 @@ export const RideModel = types
this.checkActivityAuthorizationInfo()
},
startRide(route: RouteItem) {
this.setRideLoading(true)
if (!canRunLiveActivities) return

this.setRideLoading(true)
this.setRoute(route)

startRideHandler(route)
Expand All @@ -94,6 +95,8 @@ export const RideModel = types
})
},
stopRide(rideId: string) {
if (!canRunLiveActivities) return

this.setRideLoading(true)
this.setRideId(undefined)
this.setRoute(undefined)
Expand All @@ -112,7 +115,7 @@ export const RideModel = types
self.id = rideId
},
isRideActive(rideId: string) {
if (Platform.OS === "ios") {
if (canRunLiveActivities) {
iOSHelpers.isRideActive(rideId).then((tokens) => {
// TODO: Check if ride Id exists in the array.
// Currently .rideId arrives always empty, so we only check if the array is empty.
Expand Down
3 changes: 2 additions & 1 deletion app/screens/planner/planner-screen-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { color, fontScale, spacing } from "../../theme"
import { Chip, Text } from "../../components"
import { useStores } from "../../models"
import { isRTL } from "../../i18n"
import { canRunLiveActivities } from "../../utils/ios-helpers"

const HEADER_WRAPPER: ViewStyle = {
flexDirection: "row",
Expand Down Expand Up @@ -46,7 +47,7 @@ export const PlannerScreenHeader = observer(function PlannerScreenHeader() {
useEffect(() => {
// display the "new" badge on ios devices if the user has stations selected (it's not the
// initial launch) and they haven't seen the live announcement screen yet
if (routePlan.origin && routePlan.destination && Platform.OS === "ios") {
if (routePlan.origin && routePlan.destination && canRunLiveActivities) {
storage.load("seenLiveAnnouncement").then((hasSeenLiveAnnouncementScreen) => {
if (!hasSeenLiveAnnouncementScreen) setDisplayNewBadge(true)
})
Expand Down
5 changes: 3 additions & 2 deletions app/screens/route-details/components/start-ride-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import crashlytics from "@react-native-firebase/crashlytics"
import { Button } from "../../../components"
import { isRTL, translate } from "../../../i18n"
import { RouteItem } from "../../../services/api"
import { differenceInMinutes, isAfter, set } from "date-fns"
import { differenceInMinutes, isAfter } from "date-fns"
import { timezoneCorrection } from "../../../utils/helpers/date-helpers"
import { color } from "../../../theme"
import { useStores } from "../../../models"
import { canRunLiveActivities } from "../../../utils/ios-helpers"

const { width: deviceWidth } = Dimensions.get("screen")

Expand Down Expand Up @@ -62,7 +63,7 @@ export const StartRideButton = observer(function StartRideButton(props: StartRid
const isRouteInFuture = differenceInMinutes(route.departureTime, timezoneCorrection(new Date()).getTime()) > 60

const activeRide = !!ride.id
const areActivitiesDisabled = !(ride?.activityAuthorizationInfo?.areActivitiesEnabled ?? true)
const areActivitiesDisabled = !canRunLiveActivities || !(ride?.activityAuthorizationInfo?.areActivitiesEnabled ?? true)
const isStartRideButtonDisabled = isRouteInFuture || isRouteInPast || areActivitiesDisabled || activeRide

const shouldDisplayFirstRideAlert = async () => {
Expand Down
3 changes: 2 additions & 1 deletion app/screens/route-details/route-details-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { RouteStationCard, RouteStopCard, RouteLine, RouteExchangeDetails } from
import { LiveRideSheet, LongRouteWarning, StartRideButton } from "./components"
import BottomSheet from "@gorhom/bottom-sheet"
import { FirstRideAlert } from "./components/first-ride-alert"
import { canRunLiveActivities } from "../../utils/ios-helpers"

const ROOT: ViewStyle = {
flex: 1,
Expand Down Expand Up @@ -137,7 +138,7 @@ export const RouteDetailsScreen = observer(function RouteDetailsScreen({ route }
)}

{/** TODO: Remove iOS Check */}
{Platform.OS === "ios" && !isRideOnThisRoute && (
{canRunLiveActivities && !isRideOnThisRoute && (
<Animated.View entering={shouldFadeRideButton && FadeInDown.delay(100)} exiting={FadeOutDown} style={{ flex: 1 }}>
<StartRideButton route={routeItem} screenName={route.name} openFirstRideAlertSheet={openFirstRideAlertSheet} />
</Animated.View>
Expand Down
5 changes: 4 additions & 1 deletion app/utils/ios-helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { NativeModules } from "react-native"
import { NativeModules, Platform } from "react-native"
import { RouteItem } from "../services/api"

const { RNBetterRail } = NativeModules

export const canRunLiveActivities = Platform.OS == "ios" && parseFloat(Platform.Version) >= 16.2

export function donateRouteIntent(originId: string, destinationId: string) {
RNBetterRail.donateRouteIntent(originId, destinationId)
}
Expand Down Expand Up @@ -96,5 +98,6 @@ export default {
startLiveActivity,
endLiveActivity,
isRideActive,
canRunLiveActivities,
activityAuthorizationInfo,
}
20 changes: 10 additions & 10 deletions ios/BetterRail.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = BetterRail/BetterRailDebug.entitlements;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = UE6BVYPPFX;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -1196,7 +1196,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = UE6BVYPPFX;
INFOPLIST_FILE = BetterRail/Info.plist;
Expand Down Expand Up @@ -1359,7 +1359,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=watchos*]" = UE6BVYPPFX;
Expand Down Expand Up @@ -1401,7 +1401,7 @@
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=watchos*]" = UE6BVYPPFX;
Expand Down Expand Up @@ -1437,7 +1437,7 @@
CODE_SIGN_ENTITLEMENTS = "WatchBetterRail Extension/WatchBetterRail Extension.entitlements";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=watchos*]" = UE6BVYPPFX;
Expand Down Expand Up @@ -1478,7 +1478,7 @@
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=watchos*]" = UE6BVYPPFX;
Expand Down Expand Up @@ -1516,7 +1516,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = BetterRailWidgetExtensionDebug.entitlements;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = UE6BVYPPFX;
Expand Down Expand Up @@ -1557,7 +1557,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = UE6BVYPPFX;
Expand Down Expand Up @@ -1590,7 +1590,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = StationIntent/StationIntentDebug.entitlements;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = UE6BVYPPFX;
Expand Down Expand Up @@ -1629,7 +1629,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = UE6BVYPPFX;
Expand Down
2 changes: 1 addition & 1 deletion ios/BetterRail/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>3</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationQueriesSchemes</key>
Expand Down
2 changes: 1 addition & 1 deletion ios/BetterRailWidget/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<string>3</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
Expand Down
2 changes: 1 addition & 1 deletion ios/StationIntent/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<string>3</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
Expand Down
2 changes: 1 addition & 1 deletion ios/WatchBetterRail Extension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<string>3</string>
<key>CLKComplicationPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ComplicationController</string>
<key>NSExtension</key>
Expand Down
2 changes: 1 addition & 1 deletion ios/WatchBetterRail/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<string>3</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down

0 comments on commit d6c134b

Please sign in to comment.