MOJi辞書之自定义小组件

实现背景

1.有用户反馈,说目前的小组件背景图不好看,是否可以自定义;
2.让用户选择自己感兴趣的单词库,兴趣是最好的老师。

可自定义的类型

1.选择背景(ImageCrop)
2.选择词库(FolderPicker)

数据的刷新方式

1.小组件自身按约定的时间周期进行刷新;
2.主项目控制小组件刷新;

以下主要讲解”主项目是怎么控制小组件刷新的?”

原理:以桥接的方式,通过OC项目使用Swift的WidgetKit框架,并调用其内部的WidgetCenter.shared.reloadAllTimelines()方法即可。

开始表演:

1.创建一个Swift文件,我们可定义为WidgetKitManager.swift;这时候会弹出一个创建桥接文件的提示,点创建即可。

2.然后把相应的代码实现添加到该Swift文件中,代码段如下:

import WidgetKit

@objc
@available(iOS 14.0, *)
open class WidgetKitManager: NSObject {

    @objc
    static let `default` = WidgetKitManager()
    @objc
    open class var shared: WidgetKitManager {
        get {
            return self.default
        }
    }
    
    /// MARK: 刷新所有小组件
    @objc
    public func reloadAllTimelines() {
       #if arch(arm64) || arch(i386) || arch(x86_64)
       
       WidgetCenter.shared.reloadAllTimelines()
       
       #endif
    }

    /// MARK: 刷新某个小组件(kind: 小组件Configuration 中的kind)
    @objc
    public func reloadTimelines(kind: String?) {
        #if arch(arm64) || arch(i386) || arch(x86_64)
       
        if kind != nil {
            WidgetCenter.shared.reloadTimelines(ofKind: kind!)
        } else {
            WidgetCenter.shared.reloadAllTimelines()
        }
        
        #endif
    }
}

3.然后对主项目进行编译运行,然后报错,信息如下:

<unknown>0: error: using bridging headers with module interfaces is unsupported. Command CompileSwiftSources failed with a nonzero exit code

感觉不对劲,因为是按照网上大部分网友的方法操作的,然后一直卡在这里。。

后面细查了下,有网友建议:在Xcode的Build Settings中找到Build Libraries for Distribution,并设置为NO即可解决。

然后我对其进行了尝试,果真编译通过可运行。突然觉得很爽,问题搞定了!

但是!!

Build Libraries for Distribution在我们发包的时候是有要求的,必须设置为YES。坑爹,该网友的方法不好使。那么怎么办?

继续找…

继续查…

还是没找到答案!!

什么Stack Overflow、什么Google,百度就算了,但连苹果开发者论坛,也是只有人问但没有人给出最佳的答案。

突然灵光一闪!⚡️⚡️⚡️

发现:
我们有好几个框架是用Swift写的,然而他们在编译运行的时候不会报错。(如:BackendConfigRawSwift.xcframework,又如MOJiWordTransformer.xcframework,该框架直接用到主项目中,而且编译运行都不会报错)

这下明白,使用Swift文件与主项目配置的Build Libraries for Distribution = YES时会有冲突(编译出错)。为解决这个冲突,需要把Swift相关实现统一封装成一个库文件(这里我们统一定义为MOJiSwiftKitManager)。

好了,明白其中道理之后,开始进行MOJiSwiftKitManager框架的实现;(这里框架实现略过)

从上面的步骤3,继续往下走…

4.主项目集成MOJiSwiftKitManager框架

5.编译主项目并运行成功!

6.这个时候我们需要一个桥接头文件,对里面的swift文件进行引用,我们创建MOJiDict-Bridging-Header.h(由于已经提示过一次桥接文件创建的弹窗,所以下次再创建Swift文件是不会提示创建了,只能手动创建桥接头文件),头文件内容主要是引用的作用,代码段如下:

@import MOJiSwiftKitManager;

目前,来到这一步,已经接近尾声…

7.最后,我们在需要使用WidgetKit的刷新方法的地方#import "MOJiDict-Bridging-Header.h",并调用[WidgetKitManager.shared reloadAllTimelines];

大功告成!!!


其他注意事项

1.WidgetKit只支持iOS 14+,所以主项目在使用时需做系统版本判断;
2.发包时确保Build Libraries for Distributions为YES;
3.为减少OC项目使用Swift或Swift项目使用OC带来的冲突,尽可能统一框架使用;

Which Are Bonuses and How to Get Them in an Internet Casino?

Every online casino gamer is aware of the excitement of winning in slots. It s no wonder that slots are so popular with online casino players. The wide range of matches, the ease of the play, and the versatility of playing on any sort of budget are all what make it such a popular game in online casinos. But what many people don’t realize is that you will find an assortment of bonuses which are supplied in slots also. Bonuses are basically extra cash that online casino casinos give players to help them get started using their slots encounter.
goldenstar-casino.com
There are a lot of different items that may offer you bonuses in slots. These bonuses may include jackpot dimensions gains, additional time to play, or even a opportunity to win a slot game after playing with it. Anytime that you increase your probability of winning, you’re boosting your payout. This is one way that you can raise your probability of getting more cash off of your gaming experience. In the event you win a slot after just playing a few times, you stand a fantastic chance of receiving an extra payout. This is only because jackpots have a propensity to maintain their payouts consistent regardless of how much you play.

Along with the free spins, you can also win free spins with only spending a certain amount of money. Free spins are pretty easy to understand because the quantity of money which you need to spend so as to acquire a bonus is rather small. The most common free spins on the internet casinos sequential spins on a single jackpot slot. This allows you to build up some cash while enjoying and offers you the opportunity to see whether you’re able to win more in the long run by playing.

Another thing that you may choose to think of when you’re taking a look at online slots would be the”probationary” periods. These periods normally last for a specific amount of time. You will not be qualified to wager on any slot games during this time, and that means you’re not really losing anything if you do not participate in such times. They do not interfere with your ability to win, but they don’t benefit you in any manner either.
Which Are Bonuses and How to Get Them in an Net Casino?
Whenever you’re contemplating the bonuses provided by online casinos, then remember that there may be some free slots involved also. At some casinos you will see special features that permit you to play with without having to play with money. These attributes are called bonuses. While these might not offer you a significant payoff, they do offer you a means to improve your chances of obtaining a good slot machine jackpot payout.

Some people decide to play slots since they like the challenge of trying to beat the odds. You do have some control over the odds by playing and betting many different combination after combination. In addition to earning cash through jackpots and bonus rounds, you can also win cash just by playing the device. Most slot games permit you to play for up to ten minutes at one time, at which point you may stop and play another game. The amount of time you’ll be able to play may vary but is limited to the amount of time you need to playwith.