iOS 16 Live Activities Lock Screen widget

  • Set the apns-topic header field of the request you sent to APNs using the following format: <your bundleID>.push-type.liveactivity.

    bundleID is main app's bundleID? or the widget's bundleID?

Add a Comment

Apple Recommended

  • @DeveloperToolsEngineer, do you know if there will be a new framework tag for "ActivityKit" made available in the forums?

  • Set the apns-topic header field of the request you sent to APNs using the following format: .push-type.liveactivity. bundleID is main app's bundleID? or the widget's bundleID?

Add a Comment

Replies

I asked the same thing during WWDC22 Labs and the API behavior and design is pretty much on lock down.

Taking hints from the system and the use cases that Apple has demonstrated, a package delivery, a sports event score change, a ride share service, these are all things that seem to be remote server updated. Meaning the phone can't do them on their own. Maybe you could do a conference planner/scheduler Live Activity that is all locally cached, but the use cases were telling to me. I have to imagine it will look like WidgetKit but have some aspect of content-available push that maybe goes right to your widget / live activity extension. Or to your app and then reload timeline if truly like widget kit.

I'd also bet that just like widgets on home and Lock Screen, Live Activities will be 100% SwiftUI for visuals. So my vote goes to learning "systemMedium" widget family, and SwiftUI. If you make a systemMedium Home Screen widget visually, hopefully it would be reusable for your live activity view.

Out of curiosity, what is your use case? How often would you want to refresh the live activity? This was also something I talked about in my lab, trying to get info on refresh policies--nothing :) Guess we will have to wait. I was encourage to #filefeedback on my ideas for Live Activities so Apple can see what we want to build.

It looks like Live Activities is a combination of push notifications (initiated locally or remotely) into a single widget-like notification. So updates are triggered with notifications and the element itself will more likely act as a widget. It is unclear if button elements are allowed for direct control (as we see in music activity). If not then it's pure mid-size widgets, so I'd start with building a widget for your app.

  • @DeveloperToolsEngineer, do you know if there will be a new framework tag for "ActivityKit" made available in the forums?

  • Set the apns-topic header field of the request you sent to APNs using the following format: .push-type.liveactivity. bundleID is main app's bundleID? or the widget's bundleID?

Add a Comment

Is there some documentation on the errors for Live Activities? I've tried to create a sample app using the documentation article listed above. I get an error when I try to start a Live Activity. I'm not sure what it means, since I can't find any documentation on the errors.

Error requesting pizza delivery Live Activity The operation couldn’t be completed. (com.apple.ActivityKit.ActivityInput error 1.)
  • try this: Open your app’s Info.plist file and add an entry with the key NSSupportsLiveActivities of type Boolean with the value YES.

  • Thanks @haozes! that fixed the issue for me! By mistake i added to the extension plist instead of the app target plist

  • Thanks @haozes. I had added that to my extension target by mistake instead of the app target.

Add a Comment

I have been testing the Live Activity API using the latest betas and the activity is saying it is started correctly, but is only displayed if it is the only widget in the extension. Can you have multiple widgets and live activities at the same time? I am also never getting a push token when starting the activity despite having push setup and being on an eligible machine according to the note in the doc. Has anyone gotten a live activity to properly display and/or a push token?

  • I have only gotten the activity to show for requests that set the push token to nil. I haven't explored the push based activity very far yet. Note the default value of the pushType parameter is to set to push, so ensure you set it to nil if you want local. For my "local only" activities, I've also experience the simulator not showing them (FB11064112). I would encourage you to file a feedback too and post the number in here.

  • I get pushtoken is nil all the time, how do you get it

Add a Comment

I have gotten it to show on a real device and have gotten push tokens now. It does seem like you are not able to start a live activity from the background which was not documented. If anyone has a way to do this that would be great to know!

  • Have the same problem here , cann't update live activity from background

  • From the documentation you can START an activity only from the foreground. Given push, and the nature of the activity, you should be able to UPDATE from the background. I plan to test this out and file feedback if I can't get it to work. @haozes, what background capability are you using that you're trying to update from the background?

  • Hey , seeing a crash on this ActivityAuthorizationInfo().areActivitiesEnabled when trying to run on real device. On simulator it works fine. Any help here on how to resolve?

let pushTokenString = String(deviceToken: self.statusActivity?.pushToken ?? Data())

extension String {
  public init(deviceToken: Data) {
    self = deviceToken.map { String(format: "%02x", $0) }.joined()
  }
}

→ POST https://api.sandbox.push.apple.com:443/3/device/800e9f97bb01fd62cf0ded1a546a3061c3dd09501068b8bedf05a1c4e23562c90c4c04e6c751b4b261687c03b4f87941959572c021bb3546bf441056a50ac65584eb790b10f35d15d7776da7268bbea7 apns-priority:10 apns-push-type:alert apns-topic:com.ustc.jerryliu.liveactivitiesdemo

{
  "aps" : {
    "event" : "update",
    "content-state" : {
      "homeScore" : 2,
      "estimatedEndTime" : 1660559974,
      "guestScore" : 2,
      "halfInfo" : "next"
    },
    "timestamp" : 1660556374
  }
}

← 400 apns-id:2E014A5B-EF1B-50AB-BA37-83A236C836F6

{ "reason" : "DeviceTokenNotForTopic" }

the push token not work,but the normal push word well Is there something wrong with the token?

  • Same here

  • same here

  • same issue here..do we need a new recreate the certificate with push enabled because of the live activity?

How does a user enable/disable the feature? Is it a part of Focus as well?

  • @Gama_, right now the behavior is you request an activity and if your code is good and device setup correct, you're granted in first time without a permission prompt. There is a toggle in Settings > Your App > Live Activities, but I've created a feedback for an explicit user permission prompt. FB11210596

Add a Comment

Is there any way to load images from a URL (support updatable images) for Live Activity?

I know that from the doc "Each Live Activity runs in its own sandbox, and — unlike a widget — it can’t access the network or receive location updates." but supporting updatable images would be a very useful feature.

Also interesting that OneSignal mentioned here (https://onesignal.com/blog/using-ios-16-live-activities/) that "You can, however, still load images from a URL on demand into your Live Activity. The image URL could be part of the activity content that changes."

But passing URL & using AsyncImage doesn't work for me. Any ideas?

  • I cannot get images to dynamically load, only via stored assets.

  • AsyncImage still doesn't work on 16.1 beta 2. This looks like something that should work considering there is no other way to access the network.

  • only way I've gotten images to load is by saving to userdefaults and then using same group namespace to access.

Add a Comment

I am able to build this on simulator but when built on device facing crash in this line

let areActivitiesAllowed = ActivityAuthorizationInfo().areActivitiesEnabled

Using iOS 16 beta 4. Anyone facing same?

For simulator push token is nil. How can we test this?

Upgraded to iOS16 beta yesterday and trying this, facing the same crash. Cant surpass this. On Simulator how ever it doesnt happen. Any leads here?

ActivityAuthorizationInfo().areActivitiesEnabled -> Crashing

Has ActivityKit been removed? The links direct to WidgetKit or 404s.

  • As ActivityKit is not gonna be available on iOS 16 release, you should use Xcode Beta in order to keep working with ActivityKit as its "beta exclusive" for now.

  • Is it working in iOS 16 beta 4?

Add a Comment

Where is the document for ActivityKit? Xcode 14 RC also can't import ActivityKit

  • @Pulin I think it was described in the Platform State of the Union that ActivityKit would be available later this fall. If you want to keep developing against it, use Xcode 14 Beta 6, or wait for Xcode 14.1 Betas to release.

Add a Comment

Is there a way to get iOS 16 Beta 6? I got Xcode beta 6 but simulator cannot be used to test getting a push token or test Live Activity with remote pushes

When creating an iOS live activity with Activity.request(attributes: , contentState: initialContentState, pushType: .token ) I get the error: The operation couldn’t be completed. (com.apple.ActivityKit.ActivityInput error 0.). but no error while I change pushType to nil I am sure I have requested Notification with [.sound, .badge, .alert] right