I am trying to show unity ads in my ios project. I am using SwiftUI (Not AppDelegate, not Storyboard). There are not much examples on the web, and the little of them there are old and does not support showing ads with swiftui. Even the unity documentation website does not support it yet. please help me, I get this error from my show ads method and the code won't build: Cannot convert value of type 'UIViewController.Type' to expected argument type 'UIViewController'
import SwiftUI
import UnityAds
//Initialize Unity ads here
UnityAds.initialize("307659", testMode: true)
func loadInterstitial_UnityAds(){
if UnityAds.isInitialized(){
UnityAds.load("video")
}
}
func showAds_Unity(){
UnityAds.show(UIViewController, placementId:"307659", showDelegate: nil)
}
Related
Is it possible to disable RealityKit/ARKit/AR when building for xcode Simulator? So that I can style/change non-ar related pages.
I want to change my home page, adding different sections and styling. The home page has nothing to do with ARKit/Reality Kit, but I don't have the physical device with me.
The errors say that various RealityKit/ARKit functions are undefined or don't exist. Like ARView has no member .occlusion.
The home page has no need for AR at all, is it possible to build and run the simulator, or even preview without a physical (AR Enabled) device?
You can use a Conditional Compilation Block, as explained in the Swift Programming Manual:
class SubclassedARView : ARView {
var configuration: ARWorldTrackingConfiguration()
var runOptions: ARSession.RunOptions()
init() {
#if !targetEnvironment(simulator)
// Code here is only compiled when building to a real or generic device.
// This is the place where you should add your RealityKit specific
// code, or at least the code that gives build-time errors in Xcode.
// An example of a problematic method:
session.run(configuration, options: runOptions)
#endif
}
}
Trying to learn React Native custom Native UI Components.
// FridgeCameraViewManager.swift
import UIKit
#objc(FridgeCameraViewManager)
class FridgeCameraViewManager: RCTViewManager {
override func view() -> UIView! {
let label = UILabel()
label.text = "Swift Component"
label.textAlignment = .center
return label
}
#objc static override func requiresMainQueueSetup() -> Bool {
return false
}
}
.
// FridgeCameraViewManager.h
#import <Foundation/Foundation.h>
#import "React/RCTViewManager.h"
#interface RCT_EXTERN_MODULE(FridgeCameraViewManager, RCTViewManager)
#end
.
// FridgeCameraView.js
import {requireNativeComponent} from 'react-native';
const FridgeCameraView = requireNativeComponent('FridgeCameraView', null);
export default FridgeCameraView;
When I try to use FridgeCameraView component somewhere in App.js, it works only If I build & run the project using Xcode. Otherwise, using hot reload when changing something, I get "Invariant Violation: tried to register two views with the same name FridgeCameraView".
Somehow, the error went away when I installed react-router-native. I think there was a package conflict or something that I was missing. Hopefully, this will be a fix for the ones who encounter this error in the future. I'm still waiting for explanations if somebody knows what's behind this weird error.
(Not a solution, but still want to contribute)
TL;DR:
Just press R in terminal to refresh app
Auto hot-reload will register FridgeCameraView twice, reason unknown
For those of you who are wondering what's going on, we're learning the React Native - iOS Native Component and following the tutorial:
Swift in React Native - The Ultimate Guide Part 1: Modules
Swift in React Native - The Ultimate Guide Part 2: UI Components
And this is part 2 UI Components that went wrong. As React / React Native are changing fast, this scared resource on native component soon became outdated.
I accidentally need to reinstall my macOS & node_module, no luck in getting rid of the error. Installing another package doesn't solve the issue either.
I suspect that during React Native bridging in Swift -> Objective C -> React-JS, React Native will register our customized module FridgeCameraView twice; but will need expect in Objective C to dig deeper on this issue. Any contribution is welcomed!
I am currently working on a project in which I need to implement a graphical framework that has been written for Android and iOS; however, I am writing the application using Flutter/Dart, and so far I can not find any way for showing native iOS views in a Flutter application. I have found a module written for android that claims to do this (blog post), and I am curious if anyone knows of any modules or techniques that can achieve this for iOS.
I know that Flutter has the ChannelMethod feature, but that is not a solution-at least from my understanding, ChannelMethods can pass platform-specific messages, but this does not help me show a platform-specific plugin in a Flutter application.
It has also occurred to me to hard code an equivalent graphic interface in Flutter and then use ChannelMethods to pass the needed data, but this is not ideal because it appears that not all data I would need from the plugin is easily available. I'm really looking for a way to show the UIView in Flutter somehow.
Is there any way to show a native iOS view in a Flutter application?
Alternatively, is there any way to segue to a iOS viewController from a Flutter application?
You can use Flutter Platform Views to display platform native widgets in the Flutter app.
In the sample given in the docs, FLNativeViewFactory creates the platform view, and it provides a reference to the UIView. The iOS Views can be added using the provided UIView reference.
Using Swift
class FLNativeView: NSObject, FlutterPlatformView {
init(
frame: CGRect,
viewIdentifier viewId: Int64,
arguments args: Any?,
binaryMessenger messenger: FlutterBinaryMessenger?
){
_view = UIView()
super.init()
// iOS views can be added here
}
}
Using Objective-C
#implementation FLNativeView {
UIView *_view;
}
- (instancetype)initWithFrame:(CGRect)frame
viewIdentifier:(int64_t)viewId
arguments:(id _Nullable)args
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger {
if (self = [super init]) {
_view = [[UIView alloc] init];
}
// iOS views can be added here
return self;
}
#end
I have an iOS application that is providing Document Picker feature working perfectly on iOS 10 but that on iOS 11 always calls the documentPickerWasCancelled: with this message in logs:
[UIDocumentLog] UIDocumentPickerViewController : didPickDocumentURLs
called with nil or 0 URLS
I'm correctly calling dismissGrantingAccessToURL: with a valid NSURL on the provider extension but it never calls the documentPicker:didPickDocumentsAtURLs: on the other side.
I think I'm missing something, can you give me an explanation for this bad behaviour?
I'm having the same problems. Unfortunately I think the explanation is a bug or backwards-incompatibility in iOS 11. According to the documents it should be enough with a Document Picker extension:
"The Document Picker View Controller extension can perform import and export operations on its own. If you want to support open and move operations, you must pair it with a File Provider extension."
https://developer.apple.com/documentation/uikit/uidocumentpickerextensionviewcontroller?language=objc
And indeed this worked fine in iOS 10 and earlier. iOS 11 was probably meant to be backwards compatible with the existing FileProvider-less DocumentPickers, but seems it's not. Or perhaps they forgot to update the documents.
Instead, one can implement the new updated File Provider that gives access to your files via the standard document browser UI:
https://developer.apple.com/documentation/fileprovider
This does work with an iOS 11 FileProvider backing the iOS10 picker. You probably want to create a new FileProvider using the new Xcode template, then use :
#available(iOSApplicationExtension 11.0, *)
on the FileProviderItem and FileProviderEnumerator classes, then :
if #available(iOSApplicationExtension 11.0, *) {
in the methods on your FileProviderExtension
I find that my iOS 10 picker does correctly call this method, but note the completionHandler?(nil) was required to make it work. By default, the template for iOS11 inserts a completion that reports a failure. This code works for me:
override func startProvidingItem(at url: URL, completionHandler: ((_ error: Error?) -> Void)?) {
completionHandler?(nil)
// completionHandler?(NSError(domain: NSCocoaErrorDomain, code: NSFeatureUnsupportedError, userInfo:[:]))
}
However, that isn't the end to this iOS10/11 incompatibility. If you make an iOS10/11 compatible file provider, it won't run on some iOS10 devices as far as I can see. I can run or debug mine on a 32-bit iOS device, but the FileProvider crashes on a 64-bit iOS 10 device with this error:
dyld: Library not loaded: /System/Library/Frameworks/FileProvider.framework/FileProvider
Referenced from: /private/var/containers/Bundle/Application/61BBD1A7-EA1E-4C10-A208-CA1DFA433C8D/test.app/PlugIns/testFileProvider.appex/testFileProvider
Reason: image not found
I am looking at a camera tutorial for IOS and the CGDataProviderCreateWithCFData function was used. However Xcode doesn't seem to recognize it. Was this function removed from the latest Xcode Swift update? I am using Xcode version 8.1 and Swift 3. Also I have the following imports:
import UIKit
import AVFoundation
Have you tried searching "CGDataProviderCreateWithCFData" in the Apple's API reference page?
When I tried, I was guided to the Objective-C page, and its Swift link shows:
Initializer
init(data:)
Creates a data provider that reads from a CFData object.
In Swift 3, CGDataProviderCreateWithCFData is imported as an initializer of CGDataProvider and use it as:
let dataProvider = CGDataProvider(data: imageData as CFData)
(Assuming imageData as a Data.)
You can use it with import UIKit.