Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

今日天气 (TodayWeather)

一个基于 iOS 的天气应用,使用 OpenWeatherMap API 获取全球城市的天气数据。

功能特性

  • 📍 自动获取当前位置的天气信息
  • 🔍 支持搜索全球任意城市的天气
  • 🔄 下拉刷新更新天气数据
  • 🌙 支持深色模式
  • 🎨 显示天气图标和详细信息(温度、湿度、风力等)
  • ⚡ 实现缓存机制,减少网络请求
  • 📱 支持左右滑动查看多个城市的天气

演示截图

主界面 城市列表 搜索功能 多城市视图
主界面 城市列表 搜索功能 多城市视图

技术栈

  • Swift
  • UIKit
  • CoreLocation (位置服务)
  • OpenWeatherMap API

安装步骤

  1. 克隆仓库

    git clone https://github.com/iqiqiya/TodayWeather.git
    cd TodayWeather
  2. 创建 API 配置文件

    由于 API 密钥是敏感信息,仓库中不包含配置文件,需要手动创建。

    • TodayWeather/Config/ 目录下创建 APIConfig.swift 文件:

      mkdir -p TodayWeather/Config
      touch TodayWeather/Config/APIConfig.swift
    • 编辑 APIConfig.swift 文件,添加以下内容(替换为你的 OpenWeatherMap API 密钥):

      import Foundation
      
      struct APIConfig {
          static let openWeatherMapAPIKey = "YOUR_API_KEY_HERE" // 替换为你的 OpenWeatherMap API 密钥
      }
  3. 在 Xcode 中打开项目

    open TodayWeather.xcodeproj
  4. 运行项目

    • 选择目标设备(模拟器或真机)
    • 点击 "Run" 按钮或按 Cmd+R 运行项目

获取 OpenWeatherMap API 密钥

  1. 访问 OpenWeatherMap 官网
  2. 注册或登录账号
  3. 进入 "API Keys" 页面
  4. 复制你的 API 密钥
  5. 将密钥粘贴到 APIConfig.swift 文件中

使用说明

  • 查看当前位置天气:应用启动后会自动获取并显示当前位置的天气
  • 搜索城市天气:点击左上角的搜索按钮,输入城市名称,点击搜索
  • 查看城市列表:点击右上角的列表按钮,查看已添加的城市
  • 左右滑动查看城市:在主界面左右滑动,可以查看已添加的多个城市的天气
  • 刷新天气数据:下拉屏幕刷新天气数据
  • 切换深色模式:在系统设置中切换外观模式,应用会自动适应

项目结构

TodayWeather/
├── Config/                  # 配置文件目录
│   └── APIConfig.swift      # API 密钥配置(需手动创建)
├── Models/                  # 数据模型
│   ├── WeatherModel.swift
│   └── City.swift           # 城市数据模型
├── Services/                # 服务类
│   ├── LocationService.swift
│   ├── WeatherService.swift
│   └── CityStorageService.swift  # 城市存储服务
├── ViewController.swift     # 主视图控制器
├── TodayWeather.xcodeproj   # Xcode 项目文件
└── 演示图片/                # 演示截图
    ├── Simulator Screenshot - iPhone 17 Pro - 2026-02-25 at 19.06.32.png
    ├── Simulator Screenshot - iPhone 17 Pro - 2026-02-25 at 19.06.39.png
    ├── Simulator Screenshot - iPhone 17 Pro - 2026-02-25 at 19.06.57.png
    └── Simulator Screenshot - iPhone 17 Pro - 2026-02-25 at 19.07.12.png

注意事项

  • API 密钥安全:请不要将你的 API 密钥提交到版本控制系统
  • 位置权限:首次运行时会请求位置权限,请允许以获取当前位置的天气
  • 网络连接:需要网络连接才能获取天气数据

许可证

MIT License

About

iOS端今日天气App

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages