Coder Social home page Coder Social logo

pawello2222 / widgetexamples Goto Github PK

View Code? Open in Web Editor NEW
779.0 8.0 75.0 14.16 MB

A demo project showing different types of Widgets created with SwiftUI and WidgetKit.

License: MIT License

Swift 91.47% C 8.50% Objective-C 0.02%
swift swiftui widget widgetkit coredata userdefaults deeplinks ios14 ios14-widget sirikit

widgetexamples's Introduction

Hi there 👋

Pawel.me App Store Stack Overflow LinkedIn Tersacore

Stats Stats

Currently working on iOS apps and frameworks. Passionate about Swift and SwiftUI.

Open-source projects

Appliable   PhantomKit   XFormatter   Widget Examples   XFormatter

Profile views

widgetexamples's People

Contributors

pawello2222 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

widgetexamples's Issues

Data sharing from iOS app to Lock Screen widget and Watch widget

Hi bro, thanks for these examples.

I'm working on iOS 16 / watchOS 9 Widget these days.
Before, I have a Watch Complications (ClockKit), it gets data from iOS app every 10 mins through WatchConnectivity, it works well.
But on watch 9, it needed to migrate to WidgetKit (Migrating ClockKit complications to WidgetKit), then WatchConnectivity doesn't work anymore, shows error "Companion app is not installed".
I have also tried share data on App Group UserDefault between iOS app and Watch Widget, but when read data on widget it shows error "[User Defaults] Couldn't read values in CFPrefsPlistSource<0x...> (Domain: group.com...., User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd"

I'm trying to use intent to configure/update widget data (Making a Configurable Widget), but I'm not sure if it can update my Widget every 10 mins, or Intents is not for this use at all.

If not, the only way is use URLSession to request data from http server.

So do you have any suggestions base on your experience,

Thank you from your time

iOS clock animations on homescreen widget

I want to add a homescreen widget to my app, just like the iOS system Clock app, the second hand keeps moving every second. I have been searching on Google and Github for a long time and have not found a suitable solution. I have seen that there are already third-party apps that can implement such desktop widgets.

Do you know how do they do it?

Custom search collection

In xcode 14, when create widget, I can use IntentHandler to custom search collection, but for AppIntentTimelineProvider I can't find the relevant documentation, can you give me some idea?

Play/Pause audio from widget

Hey @pawello2222

Thanks for this amazing repo! It helps a lot.

Currently, I'm trying to implement ability of control music in my main app from widget.
So far I found a lot of problems in this direction:

So I was wondering if you could share an example specially for audio playback?

Question about coreDataStack

Hello pawello2222,

Sorry for asking you question via Github, just created a SF account and have no permission to add comment.

I am trying to show core data with widget, and I have viewed lots of your answers on the SF. I am currently using the Presistence which is generated by the Xcode when I select the Swift lifecycle.

I set Target Membership of Presistence.swift to the host app and the widget, but I don't implement the coreDataStack. I declare one in the root view of the host app and one in the coreDataManger. The coreDataManager is in this post [https://stackoverflow.com/questions/63991081/how-to-ensure-widgetkit-view-shows-correct-results-from-fetchrequest]

After adding the host app and the widget to a same app group, the widget can show the core data which I fetch. But it also break the iCloud sync. Before I did this, the iCloud sync is working. Would you like to help me? Must I implement a coreDataStack?

`
struct PersistenceController {
// MARK controller
static let shared = PersistenceController()
// MARK container
let container: NSPersistentContainer

// MARK init
init(inMemory: Bool = false) {
    container = NSPersistentCloudKitContainer(name: "database_app")
    if inMemory {
        container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
    }
    let storeURL = AppGroup.facts.containerURL.appendingPathComponent("database_app.sqlite")
    let description = NSPersistentStoreDescription(url: storeURL)
    let description1 = container.persistentStoreDescriptions.first
    description1?.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
    container.persistentStoreDescriptions = [description]
    
    container.loadPersistentStores(completionHandler: { (storeDescription, error) in
        if let error = error as NSError? {
            fatalError("Unresolved error \(error), \(error.userInfo)")
        }
    })
    // MARK enable iCloud
    container.viewContext.automaticallyMergesChangesFromParent = true
    container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
}

}
`

And in the root view of the host app and the coreDataManager, I declare like this:
let persistenceController = PersistenceController.shared

URLImageView Cache images

Your example is great, but the URLImageView example can add an image cache, so if it's the same URL, it doesn't load the network

Adding onDelete on List ForEach

Hi there! I know this isn't an issue, but more of a new feature.

But I’m wondering how you would add the feature for onDelete for List on the ForEach(contacts.indices...) under “dynamicIntentWidgetSection"?

So you would be able to swipe and delete for example “Friend 2”?

I have tried but just getting Index out of range error. I have searched at Stackoverflow but can't get the solutions to work.

CoreData widget example

Hi there, thanks for the core data widget example! It works in my project, however I'm trying to have the widget display images from CoreData. For example, say I had an entity Person with an attribute of image, how would that change the FetchRequest (which in your example fetches the count)?

I've tried adding something like
@FetchRequest(entity: Person.entity(), sortDescriptors: []) var person: FetchedResults<Person>
and then returning the "person.image" attribute on the Widget's var body but it says
Value of type 'FetchedResults' has no member 'image'

I have my Core Data functioning in an App Group, but just can't seem to get over the final hurdle. Thanks!

iOS17的小组件时间线刷新问题

你好。这是iOS17的小组件时间线接口,我需要先显示正在加载页面,然后网络请求后,显示成功页面,.但是发现只显示了正在加载页面,而不会再次刷新进入成功页面。如何做到我想要的效果,感谢!!!
func timeline(for configuration: EmergencyAlarmWidgetIntent, in context: Context) async -> Timeline {
//通过设置枚举来区分页面
switch AlarmIntentType.type {
case .ringingAlarm, //正在报警
// 这里是异步的网络请求代码
soundAlarm(context: context) { result in
//修改状态,显示成功页面
AlarmIntentType.type = .alarmSuccess
return Timeline(entries:[Entry(date:Date()),type: AlarmIntentType.type)], policy: .never)
}
//显示正在加载页面
return Timeline(entries:[Entry(date:Date()),type: AlarmIntentType.type)], policy: .never)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.