I used below chartboost swift code in Xcode 6.3 and getting error for didFailToLoadInterstitial line. I don't had this problem in Xcode 6.2. How to fix this in Xcode 6.3 ?
func applicationDidBecomeActive(application: UIApplication)
{
let kChartboostAppID = "5472ef8f04b01601a1a5814c";
let kChartboostAppSignature = "5b6222426e68cda48669a1d4d8246d4c3d20db9c";
Chartboost.startWithAppId(kChartboostAppID, appSignature: kChartboostAppSignature, delegate: self);
Chartboost.cacheMoreApps(CBLocationHomeScreen)
}
class func showChartboostAds()
{
Chartboost.showInterstitial(CBLocationHomeScreen);
}
func didFailToLoadInterstitial(location :CBLocation, withError error: CBLoadError)
{
}
This builds for me on Chartbeat SDK 5.2.0:
func didFailToLoadInterstitial(location: String!, withError error: CBLoadError) {
}
Related
When I run app using terminate argument (set using “Product“ / “Scheme” / “Edit Scheme…” / “Run” / “Arguments” / “Argument Passes On Launch”), a notification appears in macOS Notification Centre and app terminates.
#testapp application did finish launching
#testapp terminate mode enabled
#testapp terminating…
So far, so good… Expected.
When I click notification, app launches but userNotificationCenter is not triggered (I don’t see #testapp notification triggered in Console app, but I see following).
#testapp application did finish launching
#testapp terminating…
Not normal right? How can I fix this?
I am starting to think that this is a Big Sur bug in version 11.6.
Everything works fine on Big Sur version 11.4 (M1) and 11.5 (Intel).
Thanks for helping out!
//
// AppDelegate.swift
// Test
//
// Created by Sun Knudsen on 2021-10-22.
//
import Cocoa
import UserNotifications
#main
class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate {
func showNotification(){
let content = UNMutableNotificationContent()
content.body = "Hello"
let request = UNNotificationRequest(
identifier: UUID().uuidString,
content: content,
trigger: nil
)
UNUserNotificationCenter.current().add(request)
}
func terminate() -> Void {
DispatchQueue.main.async {
NSApp.terminate(self)
}
}
func applicationDidFinishLaunching(_ notification: Notification) {
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (allowed, error) in
NSLog("#testapp application did finish launching")
if CommandLine.arguments.indices.contains(1) && CommandLine.arguments[1] == "terminate" {
NSLog("#testapp terminate mode enabled")
self.showNotification()
self.terminate()
} else {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.terminate()
}
}
}
}
func applicationWillTerminate(_ aNotification: Notification) {
NSLog("#testapp terminating…")
}
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: #escaping () -> Void
) {
NSLog("#testapp notification triggered")
self.terminate()
completionHandler()
}
}
Test app available on GitHub at https://github.com/sunknudsen/test-app.
This issue is caused by a bug in macOS Big Sur 11.6.
Everything works as expected in macOS Big Sur 11.6.1 or macOS Monterey.
Probably a dumb question but I cannot figure how make it work. When I press scan button in my IKScannerDeviceView scan works but its delegate never gets called.
I put a breakpoint on line
print("Did scan to: \(url.path)")
Scan file appears in selected folder without problems but it never stops on breakpoint.
Am I missing something?
Just for the sake of completeness I'm using Xcode 12.2 on macOS 11.0.1
Here is my code:
import Cocoa
import ImageCaptureCore
import Quartz
class ViewController: NSViewController {
#IBOutlet weak var scannerView: IKScannerDeviceView!
var deviceBrowser:ICDeviceBrowser!
override func viewDidLoad() {
super.viewDidLoad()
self.scannerView.delegate = self
self.scannerView.mode = .advanced
self.scannerView.transferMode = .fileBased
self.deviceBrowser = ICDeviceBrowser()
self.deviceBrowser.delegate = self
self.deviceBrowser.browsedDeviceTypeMask = ICDeviceTypeMask(rawValue:
ICDeviceLocationTypeMask.local.rawValue |
ICDeviceLocationTypeMask.shared.rawValue |
ICDeviceLocationTypeMask.bonjour.rawValue |
ICDeviceLocationTypeMask.remote.rawValue |
ICDeviceLocationTypeMask.bluetooth.rawValue |
ICDeviceTypeMask.scanner.rawValue)!
self.deviceBrowser.start()
}
}
extension ViewController : IKScannerDeviceViewDelegate {
func scannerDeviceView(_ scannerDeviceView: IKScannerDeviceView!, didScanTo url: URL!, error: Error!) {
print("Did scan to: \(url.path)")
}
}
extension ViewController: ICDeviceBrowserDelegate {
func deviceBrowser(_ browser: ICDeviceBrowser, didAdd device: ICDevice, moreComing: Bool) {
if (device.type.rawValue & ICDeviceTypeMask.scanner.rawValue) == ICDeviceType.scanner.rawValue {
self.scannerView.scannerDevice = (device as! ICScannerDevice)
}
}
func deviceBrowser(_ browser: ICDeviceBrowser, didRemove device: ICDevice, moreGoing: Bool) {
device.requestCloseSession()
}
func didRemoveDevice(device: ICDevice) {
device.requestCloseSession()
}
func device(device: ICDevice, didEncounterError error: NSError?) {
print("Error")
print(error?.description ?? "----")
}
}
Apparently the following methods are not called:
func scannerDeviceView(IKScannerDeviceView!, didScanTo: ICScannerBandData!, scanInfo: [AnyHashable : Any]!, error: Error!)
func scannerDeviceView(IKScannerDeviceView!, didScanTo: URL!, error: Error!)
Implement the following method instead:
func scannerDeviceView(IKScannerDeviceView!, didScanTo: URL!, fileData: Data!, error: Error!)
I implemented some shake gesture in my WatchOS app (repo here: https://github.com/ezefranca/WatchShaker) and it was working, but I am now getting the following error in debugger:
[Gyro] Manually set gyro-interrupt-calibration to 800
what does this mean and how do I fix it?
the watchShaker(didShakeWith:) function should run when the watch is shaken, but it is not running
override func awake(withContext context: Any?) {
super.awake(withContext: context)
}
var shaker:WatchShaker = WatchShaker(shakeSensibility: .shakeSensibilityNormal, delay: 0.2)
override func willActivate() {
super.willActivate()
shaker.delegate = self
shaker.start()
getRandomNumbers()
}
override func didDeactivate() {
super.didDeactivate()
shaker.stop()
}
extension OneDiceController: WatchShakerDelegate {
func watchShaker(_ watchShaker: WatchShaker, didShakeWith sensibility: ShakeSensibility) {
self.getRandomNumbers()
}
func watchShaker(_ watchShaker: WatchShaker, didFailWith error: Error) {
print(error.localizedDescription)
}
}
Hi #noahbino I found the problem, looks like these happens when the Watch have Gyro sensors support. Following the #grimxm tip here in this answer in the version 1.0.1 I fixed that.
Thank you.
I get this error and app get crash while run CoreNFC sample code in Xcode 9.0 beta 2
dyld: Library not loaded: #rpath/CoreNFC.framework/CoreNFC
Referenced from: /var/containers/Bundle/Application/2837709C-C852-4811-B696-38F2725554D4/iOS-11-by-Examples.app/iOS-11-by-Examples
Reason: image not found
Does anyone knows how to fix this?
I combined some answers together to fix this thanks to #Chinchan Zu's comment
here is how to mark Core NFC as Optional stackoverflow question
First you make import to NFCCore in "Linked Frameworks and Libraries" as optional as in this screenshot
Then inside your code you wrap your code with this #if check. Here is the class I used
#if canImport(CoreNFC)
import Foundation
import CoreNFC
#endif
class NFCManagar: NSObject {
#if canImport(CoreNFC)
var session: NFCNDEFReaderSession?
#endif
var items = [Item]()
var completion: ((_ success: Bool, _ error: Error?)-> Void)?
func beginScanning(items: [Item], completion: #escaping (_ success: Bool, _ error: Error?)-> Void) {
self.completion = completion
self.items.removeAll()
self.items.append(contentsOf: items)
#if canImport(CoreNFC)
session = NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: true)
session?.alertMessage = "Hold your iPhone near check in/out device."
session?.begin()
#endif
}
}
#if canImport(CoreNFC)
extension NFCManagar: NFCNDEFReaderSessionDelegate {
// MARK: - NFCNDEFReaderSessionDelegate
/// - Tag: processingTagData
func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
debugPrint("Nfc is detected")
}
/// - Tag: endScanning
func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
// Check the invalidation reason from the returned error.
if let readerError = error as? NFCReaderError {
// Show an alert when the invalidation reason is not because of a success read
// during a single tag read mode, or user canceled a multi-tag read mode session
// from the UI or programmatically using the invalidate method call.
if (readerError.code != .readerSessionInvalidationErrorFirstNDEFTagRead)
&& (readerError.code != .readerSessionInvalidationErrorUserCanceled) {
debugPrint("Nfc didInvalidateWithError \(error)")
}
}
// A new session instance is required to read new tags.
self.session = nil
}
}
#endif
CoreNFC is only available on iPhone 7 and iPhone 7 Plus devices. Make sure you're running your code on one of those.
See the WWDC session and the relevant documentation for more information.
https://developer.apple.com/videos/play/wwdc2017/718/
https://developer.apple.com/documentation/corenfc
For Xcode 11 make CoreNFC.framework "Do not Embed". And also wrap your code with #if check.
I have wrote a very basic Xcode project that contains 3 targets:
- iOS target
- WatchKit app
- WatchKit extension
First of all, i do not understand why Xcode creates a second target (extension) for WatchKit app ? It seems that WatchKit app contains storyboard, and WatchKit extension contains swift code (controllers). Is there a particular reason for Xcode to design and split 2 targets instead of one single ?
Look at this very basic piece of code:
iOS controller:
override func viewDidLoad()
{
super.viewDidLoad()
if WCSession.isSupported()
{
let session = WCSession.default()
session.delegate = self
session.activate()
}
}
#IBAction func on_btn_tap(_ sender: Any)
{
if WCSession.isSupported()
{
let session = WCSession.default()
session.sendMessage(["mykey": "myvalue"], replyHandler: { (response) -> Void in
NSLog("OK")
}, errorHandler: { (error) -> Void in
NSLog("Error)
})
}
}
On watch extension (InterfaceController.swift):
override func awake(withContext context: Any?)
{
super.awake(withContext: context)
if WCSession.isSupported()
{
let session = WCSession.default()
session.delegate = self
session.activate()
}
}
extension InterfaceController: WCSessionDelegate
{
func session(_ session: WCSession,
activationDidCompleteWith activationState: WCSessionActivationState,
error: Error?)
{
}
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: #escaping ([String : Any]) -> Void)
{
self.btn.setBackgroundColor(UIColor.yellow)
}
}
As you certainly understand, i have a button on my iOS App. When i tap on this button, i send a message to Watch App and this app will change a button color.
There is a delay of about 5-6 seconds between the button tap on the iPhone and the color change. Do you know why ?
In the other communication side (watch to iPhone), it is worst (10-15 seconds)
Thanks
Since you are updating your UI you need to wrap it in a DispatchQueue, like this:
DispatchQueue.main.async {
self.btn.setBackgroundColor(UIColor.yellow)
}
These delegate callbacks are not on the main thread and you should never update your UI from any other thread than the main thread. Wrapping it like this results in much faster updating of your UI and safer code.