0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[iOS][Objective-C] Objective-Cアプリ からWidgetを更新する方法

Last updated at Posted at 2021-01-13

ラッパー(swiftファイル)を用意する

WidgetKitHelper.swift

import WidgetKit
    
    @available(iOS 14.0, *)
    @objcMembers final class WidgetKitHelper: NSObject {

          class func reloadAllWidgets(){
 
            #if arch(arm64) || arch(i386) || arch(x86_64)
            WidgetCenter.shared.reloadAllTimelines()
            #endif

          }
    }

swiftコードをインポート

# import "プロダクトネーム-Swift.h"
プロダクトネームとは
  1. Projectナビゲーター (Xcodeの左側)のTargetsセクションからをアプリを選択
  2. Build Settingsタブをクリック
  3. "Product Name"で検索

これで使用できます

    if (@available(iOS 14.0, *)) {
        [WidgetKitHelper reloadAllWidgets];
    }

バックグラウンド時に更新させる場合

- (void)applicationDidEnterBackground:(UIApplication *)application {
    if (@available(iOS 14.0, *)) {
        [WidgetKitHelper reloadAllWidgets];
    }
}

参考

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?