Skip to content

logankm02/workcorner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lock In

An iOS app that helps you stay focused by sending exercise reminders when you open social media apps.

Features

  • Walking Timer: Track your exercise minutes with a simple start/stop timer
  • Daily Stats: View your total exercise minutes for the day
  • Smart Notifications: Receive reminders to exercise when you open Instagram, TikTok, or YouTube
  • Background Operation: Notifications work without opening the app
  • Privacy First: No Screen Time API required, works with free Apple Developer account

Requirements

  • iOS 16.0+
  • Xcode 15.0+
  • Free or paid Apple Developer account

Project Structure

Lock In/
├── LockInApp.swift                    # Main app entry point with TabView
├── Managers/
│   └── AppBlockerManager.swift        # State management and persistence
├── AppIntents/
│   └── ExerciseReminderIntent.swift   # App Intent for Shortcuts integration
├── Views/
│   ├── WalkingTab.swift               # Walking timer interface
│   ├── StatsTab.swift                 # Statistics display
│   └── SetupInstructionsView.swift    # Setup guide for users
├── Assets.xcassets/                   # App assets and accent color
└── Info.plist                         # App configuration

How to Build

  1. Open the Project

    open "Lock In.xcodeproj"
  2. Configure Signing

    • Select the "Lock In" target in Xcode
    • Go to "Signing & Capabilities"
    • Select your team from the dropdown
    • The bundle identifier will automatically update
  3. Build and Run

    • Select your target device or simulator
    • Press Cmd+R or click the Run button
    • Grant notification permissions when prompted

Setting Up Social Media Blocking

The app uses iOS Shortcuts automations to detect when you open social media apps and send exercise reminders.

Quick Setup

  1. Open Shortcuts App

    • Launch the Shortcuts app on your iPhone
  2. Create a New Automation

    • Tap "Automation" at the bottom
    • Tap the "+" button
    • Select "App" as the trigger
  3. Configure for Instagram

    • Choose Instagram from the app list
    • Set to "Is Opened"
    • Tap "Next"
  4. Add the Reminder Action

    • Search for "Send Exercise Reminder"
    • Add it as the action
    • Set the app name to "Instagram"
  5. Configure Automation Settings

    • Turn OFF "Ask Before Running"
    • Turn ON "Notify When Run" (optional)
    • Tap "Done"
  6. Repeat for Other Apps

    • Create similar automations for TikTok, YouTube, or any other apps
    • Each automation should have its own app name parameter

Detailed Instructions

For step-by-step instructions with explanations, tap the info button (ℹ️) in the Walk tab within the app.

How It Works

App Intent Background Execution

The app uses the App Intents framework with the following configuration:

struct ExerciseReminderIntent: AppIntent {
    static var openAppWhenRun: Bool = false  // Runs in background

    @Parameter(title: "App Name")
    var appName: String

    func perform() async throws -> some IntentResult {
        // Sends notification without opening the app
        let content = UNMutableNotificationContent()
        content.title = "Time to Exercise!"
        content.body = "\(appName) can wait. Get moving!"

        // ... notification delivery
    }
}

State Management

Exercise sessions are tracked using AppBlockerManager:

  • Walking Timer: Tracks start time and calculates elapsed minutes
  • Daily Stats: Stores total minutes with automatic midnight reset
  • Persistence: Uses UserDefaults to save state across app launches

Notification Permissions

The app requests notification permissions on launch:

UNUserNotificationCenter.current().requestAuthorization(
    options: [.alert, .sound, .badge]
)

Architecture Details

AppBlockerManager

Central state management class that:

  • Tracks walking session state
  • Calculates elapsed time
  • Persists data to UserDefaults
  • Handles day-to-day reset logic

ExerciseReminderIntent

App Intent that:

  • Accepts an app name parameter
  • Runs in background mode
  • Sends UserNotification
  • Appears in Shortcuts app automatically

Views

  • WalkingTab: Main interface with timer display and start/stop controls
  • StatsTab: Shows total exercise minutes for the current day
  • SetupInstructionsView: Comprehensive guide for setting up automations

Customization

Changing the Bundle Identifier

Edit the PRODUCT_BUNDLE_IDENTIFIER in [Lock In.xcodeproj/project.pbxproj](Lock In.xcodeproj/project.pbxproj#L600) or change it in Xcode's target settings.

Modifying the Notification Message

Edit the notification content in [Lock In/AppIntents/ExerciseReminderIntent.swift](Lock In/AppIntents/ExerciseReminderIntent.swift#L23):

content.title = "Your Custom Title!"
content.body = "Your custom message here"

Changing the Accent Color

The app uses orange as the accent color. To change it:

  1. Open [Lock In/Assets.xcassets/AccentColor.colorset/Contents.json](Lock In/Assets.xcassets/AccentColor.colorset/Contents.json)
  2. Modify the RGB values
  3. Or use Xcode's color picker in Assets.xcassets

Troubleshooting

App Intent Not Appearing in Shortcuts

  1. Build and run the app at least once on your device
  2. Wait a few minutes for iOS to index the intent
  3. Force quit and reopen the Shortcuts app
  4. Search for "Send Exercise Reminder" or "Lock In"

Notifications Not Working

  1. Check that notification permissions are granted:
    • Settings → Lock In → Notifications → Allow Notifications
  2. Verify the automation is set to run without asking:
    • Open the automation in Shortcuts
    • Ensure "Ask Before Running" is OFF
  3. Test the intent manually in Shortcuts before setting up automation

Stats Not Resetting

The app resets stats at midnight based on the device's timezone. If stats aren't resetting:

  1. Check your device's date and time settings
  2. Ensure "Set Automatically" is enabled
  3. Try force-quitting and reopening the app

Building on Free Apple Developer Account

This app is designed to work with a free Apple Developer account:

  • No App Groups required
  • No Screen Time API
  • No special entitlements needed
  • Just sign with your Apple ID in Xcode

Privacy

Lock In respects your privacy:

  • No data collection or analytics
  • No internet connection required
  • All data stored locally on your device
  • No third-party dependencies

License

This project is provided as-is for educational and personal use.

Support

For issues or questions, please refer to the in-app setup instructions or check the code documentation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages