Last active
September 20, 2022 17:51
-
-
Save ashishkakkad8/af8dada8469263f4b213f88db2cdeb6a to your computer and use it in GitHub Desktop.
Sample View to demonstrate Start Activity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import ActivityKit | |
struct ContentView: View { | |
var body: some View { | |
VStack { | |
Image(systemName: "capsule") | |
.imageScale(.large) | |
.foregroundColor(.black) | |
Text("Hello, Dynamic Island!") | |
}.onAppear(perform: { | |
startActivity() | |
}) | |
.padding() | |
} | |
func startActivity() { | |
let attributes = ActivityAttributesSample() | |
let contentState = ActivityAttributesSample.Status(value: "This is dynamic island!") | |
do { | |
let _ = try Activity<ActivityAttributesSample>.request(attributes: attributes, contentState: contentState) | |
} | |
catch (let error) { | |
print(error.localizedDescription) | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment