Unable to call Device Activity in Screen Time Api From Parent Device - ios

Using shared authorization I am able to authorize the child's device and able to see all the installed apps on the child's mobile on the parent device. But when I am trying to call DeviceActivity nothing happens. This is how I am calling DeviceActivity
class MyDeviceActivityMonitor: DeviceActivityMonitor{
override func intervalDidStart(for activity: DeviceActivityName) {
super.intervalDidStart(for: activity)
}
override func intervalDidEnd(for activity: DeviceActivityName) {
super.intervalDidEnd(for: activity)
}
override func eventDidReachThreshold(_ event:DeviceActivityEvent.Name,activity:DeviceActivityName){
super.eventDidReachThreshold(event, activity: activity)
}
}
info.plist
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.deviceactivity.monitor-extension</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).DeviceActivityMonitorExtension</string>
</dict>

I am stuck in this issue too. Have you tried changing the NSExtensionPrincipalClass to the below?
<string>$(PRODUCT_MODULE_NAME).MyDeviceActivityMonitor </string>

Related

Flutter / Swift Compiler Error (Xcode): Cannot find 'ExternalLinkAccount' in scope

Since 12th october 2022, reader's app with external account management/purchase must have to declare a new entitlement.
External Link Account
Enable qualifying apps to link to an external website for account creation or management.
https://developer.apple.com/documentation/storekit/external_link_account
I can't build because :
Swift Compiler Error (Xcode): Cannot find 'ExternalLinkAccount' in scope
Configure the SKExternalLinkAccount property list key.
<plist>
<dict>
<key>SKExternalLinkAccount</key>
<dict>
<key>*</key>
<string>https://example.com</string>
<key>jp</key>
<string>https://example.com/jp</string>
</dict>
</dict>
</plist>
Runner plist
<key>com.apple.developer.storekit.external-link.account</key>
<true/>
Runner entitlement
<plist>
<dict>
<key>com.apple.developer.storekit.external-link.account</key>
<true/>
</dict>
</plist>
ios build (with flutter run) :
Swift Compiler Error (Xcode): Cannot find 'ExternalLinkAccount' in scope
My code in a custom swift file (called with a platform specific call)
import SwiftUI
struct ExternalLinkAccountModal: View {
var body: some View {
Text("Hello, world!")
.padding()
.onAppear {
Task {
await executeTask()
}
}
}
}
struct ExternalLinkAccountModal_Previews: PreviewProvider {
static var previews: some View {
ExternalLinkAccountModal(onConfirm: nil, onCancel: nil)
.previewDevice("iPhone 13")
.previewInterfaceOrientation(.portrait)
}
}
func executeTask() async {
let basicTask = Task {
if await ExternalLinkAccount.canOpen {
do {
try await ExternalLinkAccount.open()
} catch {
print("ExternalLinkAccount.open() error \(error)")
}
}
}
}
Provisioning profile
My provisioning profile is well configured and accepted by Apple Developper :
Associated Domains, External Link Account, In-App Purchase, Push Notifications
Can you help to fix this ?
I'm using osx Ventura and ios16 platform for developping.

Adding CarPlay to a SwiftUI lifecycle app

What is the recommended way to integrate CarPlay into an app which uses a SwiftUI lifecycle ?
#main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
How do I use the CPTemplateApplicationSceneDelegate here ?
If you don't have a custom app delegate and/or scene delegate (you might need it eventually for stuff like push notifications) it should be enough to let your app know via the info.plist. You need a scene delegate for the CarPlay scene and add the following to your info.plist:
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>CPTemplateApplicationSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneClassName</key>
<string>CPTemplateApplicationScene</string>
<key>UISceneConfigurationName</key>
<string>TemplateSceneConfiguration</string>
<key>UISceneDelegateClassName</key>
<string>AppFeature.CarPlaySceneDelegate</string>
</dict>
</array>
</dict>
</dict>
The value for UISceneConfigurationName is handed to you in the scene delegate's scene(_:willConnectTo:options:) session.configuration.name.
The value for UISceneDelegateClassName has to match your CarPlay scene delegate's Type name. Note that if you encapsulate your CarPlay code in a package/framework you need to prefix the delegate's name with the module name (in this case AppFeature). If the delegate is in your app target just use CarPlaySceneDelegate.
An excerpt of the scene delegate might look like this:
class CarPlaySceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate {
let templateManager = TemplateManager() // see Apple's sample code
func templateApplicationScene(_: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController) {
templateManager.connect(interfaceController)
}
func templateApplicationScene(_: CPTemplateApplicationScene, didDisconnectInterfaceController _: CPInterfaceController) {
templateManager.disconnect()
}
}

Twitter URL Schemes set up in info.plist are throwing an exception

Someone pointed out that this was a duplicate question, Yes partly, I followed the advice in the other post and added the URLScheme as shown below, Also as suggested i forgot to add to my other target so i did and the URL twitter-13145245245624 Now what happens is my app redirects the user to their Twitter App and asks for permission to have my app use their info, once tapping the ok button user is redirected back to my app but still no Composer populates the View to Tweet. Still confused. Thanks for all the help.
let composer = TWTRComposer()
composer.setText("just setting up my Twitter Kit")
composer.setImage(UIImage(named: "twitterkit"))
// Called from a UIViewController
composer.show(from: self) { (result) in
if (result == .done) {
print("Successfully composed Tweet")
} else {
print("Cancelled composing")
}
}
This is my info.plist, however, I have no issue with posting to Facebook.
Any thoughts?
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>twitterkit-xxxxxxxxxx</string>
<string>fbxxxxxx</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>twitter</string>
<string>twitterauth</string>
</array>
Regards
J
The issue to my above question was that I did not have the below method in AppDelegate as so. This Solved my problem.
-(BOOL)application:(UIApplication*)app openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
return [[TWTRTwitter sharedInstance]application:app openURL:url options:options];
}

Can't get an item's attributes from a DynamoDB table

I have an iOS app written in Swift. In this app I'm trying to load an item from a DynamoDB table, but for some reason, I couldn't load any item, even though all the details were correct.
I have installed the AWS SDK using CocoaPods, after I followed all the instructions in order to correctly install it. I have installed the following libraries: AWSCognito, AWSCognitoIdentityProvider, AWSDynamoDB, AWSS3, AWSSNS.
After that, I have added my AWS credentials in the Info.plist file:
<key>AWS</key>
<dict>
<key>DynamoDBObjectMapper</key>
<dict>
<key>Default</key>
<dict>
<key>Region</key>
<string>USEast1</string>
</dict>
</dict>
<key>DynamoDB</key>
<dict>
<key>Default</key>
<dict>
<key>Region</key>
<string>USEast1</string>
</dict>
</dict>
<key>CredentialsProvider</key>
<dict>
<key>CognitoIdentity</key>
<dict>
<key>Default</key>
<dict>
<key>Region</key>
<string>USEast1</string>
<key>PoolId</key>
<string>myPoolId</string>
</dict>
</dict>
</dict>
</dict>
I've created a mapper file called Contact.swift:
import UIKit
import AWSDynamoDB
class Contact: AWSDynamoDBObjectModel, AWSDynamoDBModeling {
var id: String?
var name: String?
class func dynamoDBTableName() -> String {
return "Contacts"
}
class func hashKeyAttribute() -> String {
return "id"
}
}
Then, I've added the following code in ViewController.swift file, inside the viewDidLoad method. The code should get an item from a table, save its attributes, and set its name attribute to be the title of the screen:
import UIKit
import AWSDynamoDB
class ViewController: UIViewController {
//MARK: Properties
struct GlobalVars {
static let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.default()
static let id: String = "id"
static var name: String?
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
GlobalVars.dynamoDBObjectMapper.load(Contact.self, hashKey: GlobalVars.id, rangeKey: nil).continueWith(block: {(task: AWSTask<AnyObject>!) -> Any? in
if let error = task.error as NSError? {
print("The request failed. Error: \(error)")
} else if let taskResult = task.result as? Contact {
// Save the information
GlobalVars.name = taskResult.name
// Set title to the name
self.navigationItem.title = GlobalVars.name!
}
return nil
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
The problem is that the app crashes when I'm trying to assign the GlobalVars.name variable to the navigation bar title. It crashes with the following message: Fatal error: Unexpectedly found nil while unwrapping an Optional value.
I've tried to print taskResult.name instead, but it just printed nil.
But it didn't print anything to the console. I've added the following code to the Info.plist file, but that didn't work also:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>amazonaws.com</key>
<dict>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>amazonaws.com.cn</key>
<dict>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
When I'm checking in the variables area at the bottom of the editor, I can see that all of the item's attributes are nil.
After a deep search, I've noticed something very weird. When I changed the name of the table to a table which doesn't exist, I have received the following message in the console:
The request failed. Error: Error Domain=com.amazonaws.AWSDynamoDBErrorDomain Code=7 "(null)" UserInfo={__type=com.amazonaws.dynamodb.v20120810#ResourceNotFoundException, message=Requested resource not found}
When I'm running it with a correct table name, but with a wrong hash key which refers to an item which doesn't exist in the table, I don't get anything. It doesn't crashes or prints a message to the console. It just keeps running like I'm don't asking for anything from the DynamoDB table.
What can I do about it? I've already searched all over the internet but I couldn't find anything about it yet... Could you please help me solving that?
So apparently, due to a change in Swift 4 behavior change of inferencing #objc, I was supposed to add #objcMembers before the class declaration in the Contact.swift file

WebView shows blank white screen part from apple.com

I have added a web view to my app however i keep getting a blank white screen when running on simulator or even device. When i enter apple.com as the website it works perfect but for any other website it just shows a blank white screen.
import UIKit
class ViewController: UIViewController {
#IBOutlet var WebView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
var URL = NSURL(string: "http://www.apple.com")
WebView.loadRequest(NSURLRequest(URL: URL!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Have you added autolayout to your webView? As the image below shows?
Just select your webView and click on Add New Constraints and set your constraints.
If this is not your issue, check the output window if it blocks requests that are not HTTPS, then you can add this code to your info.plist code.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Update
You´re getting the white screen because you´re missing the http:// in your URL.
In Plist of the app give App Transport Security Settings,Give dictionary and then under it Allow Arbitrary Loads And set bool to YES, as in iOS 9 you have to give https request, Or simply add https with url, it will work

Resources