diff --git a/app/controllers/index.js b/app/controllers/index.js
index 8a580b9..b0652c3 100755
--- a/app/controllers/index.js
+++ b/app/controllers/index.js
@@ -3,21 +3,32 @@ import TiWidgetKit from 'ti.widgetkit';
const GROUP_IDENTIFIER = 'group.io.tidev.sample-widgetkit';
const USER_DEFAULTS_IDENTIFIER = 'kSampleAppMyData';
+const userDefaults = Ti.App.iOS.createUserDefaults({ suiteName: GROUP_IDENTIFIER });
+
+function onWindowFocus() {
+ refreshUI();
+}
+
+function refreshUI() {
+ const data = userDefaults.getObject(USER_DEFAULTS_IDENTIFIER);
+
+ $.title.text = data.title;
+ $.count.text = `${data.count}`;
+}
+
function saveData() {
- const payload = { title: 'My Title', count: 1337 };
+ const data = userDefaults.getObject(USER_DEFAULTS_IDENTIFIER);
+ const payload = { title: data.title, count: data.count + 1 };
// 1) Save data
- const userDefaults = Ti.App.iOS.createUserDefaults({ suiteName: GROUP_IDENTIFIER });
userDefaults.setObject(USER_DEFAULTS_IDENTIFIER, payload);
// 2) Refresh widget UI
TiWidgetKit.reloadAllTimelines();
+ refreshUI();
- // NOTE: The widget will show the "Default" title until your app groups are properly linked to your
- // main app and extension. Please read this article very carefully before jumping into more detail:
+ // NOTE: Please read this article very carefully before jumping into more detail:
// https://developer.apple.com/documentation/widgetkit/creating-a-widget-extension
-
- alert('Done!');
}
$.getView().open();
diff --git a/app/views/index.xml b/app/views/index.xml
index fd2b69f..7632147 100755
--- a/app/views/index.xml
+++ b/app/views/index.xml
@@ -1,7 +1,11 @@
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/extensions/SampleWidgetExtension/SampleWidgetExtension.xcodeproj/project.pbxproj b/extensions/SampleWidgetExtension/SampleWidgetExtension.xcodeproj/project.pbxproj
index fbeb76b..98bbc81 100644
--- a/extensions/SampleWidgetExtension/SampleWidgetExtension.xcodeproj/project.pbxproj
+++ b/extensions/SampleWidgetExtension/SampleWidgetExtension.xcodeproj/project.pbxproj
@@ -104,7 +104,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1340;
- LastUpgradeCheck = 1340;
+ LastUpgradeCheck = 1500;
TargetAttributes = {
3A3F7EEC286657C6005E692E = {
CreatedOnToolsVersion = 13.4.1;
@@ -156,12 +156,70 @@
3A3F7EE728665782005E692E /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ DEAD_CODE_STRIPPING = YES;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ ENABLE_USER_SCRIPT_SANDBOXING = YES;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ ONLY_ACTIVE_ARCH = YES;
};
name = Debug;
};
3A3F7EE828665782005E692E /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ DEAD_CODE_STRIPPING = YES;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_USER_SCRIPT_SANDBOXING = YES;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
};
name = Release;
};
diff --git a/extensions/SampleWidgetExtension/SampleWidgetExtension.xcodeproj/project.xcworkspace/xcuserdata/hans.xcuserdatad/UserInterfaceState.xcuserstate b/extensions/SampleWidgetExtension/SampleWidgetExtension.xcodeproj/project.xcworkspace/xcuserdata/hans.xcuserdatad/UserInterfaceState.xcuserstate
index 47b87cf..f9233fe 100644
Binary files a/extensions/SampleWidgetExtension/SampleWidgetExtension.xcodeproj/project.xcworkspace/xcuserdata/hans.xcuserdatad/UserInterfaceState.xcuserstate and b/extensions/SampleWidgetExtension/SampleWidgetExtension.xcodeproj/project.xcworkspace/xcuserdata/hans.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/extensions/SampleWidgetExtension/SampleWidgetExtension/SampleWidgetExtension.swift b/extensions/SampleWidgetExtension/SampleWidgetExtension/SampleWidgetExtension.swift
index a457278..30a4e08 100644
--- a/extensions/SampleWidgetExtension/SampleWidgetExtension/SampleWidgetExtension.swift
+++ b/extensions/SampleWidgetExtension/SampleWidgetExtension/SampleWidgetExtension.swift
@@ -8,6 +8,7 @@
import WidgetKit
import SwiftUI
import Intents
+import AppIntents
// Change to your data - this struct is just a type definition that should
// have the same structure as your saved object in your Ti.App.iOS.UserDefaults
@@ -16,15 +17,15 @@ struct MyData: Codable {
let count: Int
}
-private func fetchData() -> MyData? {
- // Change to your group that is assigned in your app and extension (via "Signing and Capabilities" > "App Groups"
- // NOTE: Your app has to have the same app group and on device, your provisioning profile should include it as well
- let GROUP_IDENTIFIER = "group.io.tidev.sample-widgetkit"
- let USER_DEFAULTS_IDENTIFIER = "kSampleAppMyData"
+// Change to your group that is assigned in your app and extension (via "Signing and Capabilities" > "App Groups"
+// NOTE: Your app has to have the same app group and on device, your provisioning profile should include it as well
+let GROUP_IDENTIFIER = "group.io.tidev.sample-widgetkit"
+let USER_DEFAULTS_IDENTIFIER = "kSampleAppMyData"
+private func fetchData() -> MyData? {
let defaults = UserDefaults(suiteName: GROUP_IDENTIFIER)
- if let archivedData = defaults?.object(forKey: USER_DEFAULTS_IDENTIFIER) as? Data, let rawData = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(archivedData) as? [String: Any],
+ if let rawData = defaults?.object(forKey: USER_DEFAULTS_IDENTIFIER) as? [String: Any],
let rawDataJSON = try? JSONSerialization.data(withJSONObject: rawData, options: .fragmentsAllowed),
let data = try? JSONDecoder().decode(MyData.self, from: rawDataJSON) {
return data
@@ -36,12 +37,18 @@ private func fetchData() -> MyData? {
struct Provider: IntentTimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
let data = fetchData()
- return SimpleEntry(date: Date(), title: data?.title ?? "Default", configuration: ConfigurationIntent())
+ return SimpleEntry(date: Date(),
+ count: data?.count ?? 0,
+ title: data?.title ?? "Counter",
+ configuration: ConfigurationIntent())
}
func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let data = fetchData()
- let entry = SimpleEntry(date: Date(), title: data?.title ?? "Default", configuration: configuration)
+ let entry = SimpleEntry(date: Date(),
+ count: data?.count ?? 0,
+ title: data?.title ?? "Counter",
+ configuration: configuration)
completion(entry)
}
@@ -53,7 +60,10 @@ struct Provider: IntentTimelineProvider {
let currentDate = Date()
for hourOffset in 0 ..< 5 {
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
- let entry = SimpleEntry(date: entryDate, title: data?.title ?? "Default", configuration: configuration)
+ let entry = SimpleEntry(date: entryDate,
+ count: data?.count ?? 0,
+ title: data?.title ?? "Counter",
+ configuration: configuration)
entries.append(entry)
}
@@ -64,6 +74,7 @@ struct Provider: IntentTimelineProvider {
struct SimpleEntry: TimelineEntry {
let date: Date
+ let count: Int
let title: String
let configuration: ConfigurationIntent
}
@@ -74,6 +85,12 @@ struct SampleWidgetExtensionEntryView : View {
var body: some View {
Text(entry.title).fontWeight(.bold)
Text(entry.date, style: .time)
+ Text("\(entry.count)")
+ if #available(iOS 17.0, *) {
+ Button(intent: ButtonCounter()) {
+ Image(systemName: "bolt.fill")
+ }
+ }
}
}
@@ -110,7 +127,26 @@ func supportedWidgetFamilies() -> [WidgetFamily] {
struct SampleWidgetExtension_Previews: PreviewProvider {
static var previews: some View {
let data = fetchData()
- SampleWidgetExtensionEntryView(entry: SimpleEntry(date: Date(), title: data?.title ?? "Default", configuration: ConfigurationIntent()))
+ SampleWidgetExtensionEntryView(entry: SimpleEntry(date: Date(),
+ count: data?.count ?? 0,
+ title: data?.title ?? "Counter",
+ configuration: ConfigurationIntent()))
.previewContext(WidgetPreviewContext(family: .systemSmall))
}
}
+
+@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *)
+struct ButtonCounter: AppIntent {
+
+ static var title: LocalizedStringResource = "Count Incrementer"
+ static var description = IntentDescription("Increments the given count!")
+
+ func perform() async throws -> some IntentResult {
+ let lastData = fetchData()
+
+ let defaults = UserDefaults(suiteName: GROUP_IDENTIFIER)
+ defaults?.set(["title": "Counter", "count": (lastData?.count ?? 0) + 1], forKey: USER_DEFAULTS_IDENTIFIER)
+
+ return .result()
+ }
+}
diff --git a/extensions/SampleWidgetExtension/SampleWidgetExtensionExtension.entitlements b/extensions/SampleWidgetExtension/SampleWidgetExtensionExtension.entitlements
index 0c67376..5c76fd1 100644
--- a/extensions/SampleWidgetExtension/SampleWidgetExtensionExtension.entitlements
+++ b/extensions/SampleWidgetExtension/SampleWidgetExtensionExtension.entitlements
@@ -1,5 +1,10 @@
-
+
+ com.apple.security.application-groups
+
+ group.io.tidev.sample-widgetkit
+
+
diff --git a/plugins/ti.alloy/hooks/alloy.js b/plugins/ti.alloy/hooks/alloy.js
index 1268281..71f7df8 100644
--- a/plugins/ti.alloy/hooks/alloy.js
+++ b/plugins/ti.alloy/hooks/alloy.js
@@ -1,6 +1,6 @@
/**
* Alloy
- * Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved.
+ * Copyright TiDev, Inc. 04/07/2022-Present
* See LICENSE for more information on licensing.
*/
diff --git a/plugins/ti.alloy/hooks/deepclean.js b/plugins/ti.alloy/hooks/deepclean.js
index dadbcb9..f6bfc2d 100644
--- a/plugins/ti.alloy/hooks/deepclean.js
+++ b/plugins/ti.alloy/hooks/deepclean.js
@@ -1,6 +1,6 @@
/**
* Alloy
- * Copyright (c) 2014 by Appcelerator, Inc. All Rights Reserved.
+ * Copyright TiDev, Inc. 04/07/2022-Present
* See LICENSE for more information on licensing.
*/
diff --git a/tiapp.xml b/tiapp.xml
index d0e340f..0f7d80f 100644
--- a/tiapp.xml
+++ b/tiapp.xml
@@ -33,6 +33,14 @@
+
+
+ com.apple.security.application-groups
+
+ group.io.tidev.sample-widgetkit
+
+
+
UISupportedInterfaceOrientations~iphone
@@ -69,7 +77,7 @@
true
true
- 10.1.1.GA
+ 12.2.0.v20230520170549
ti.alloy
\ No newline at end of file