Connecting iOS app with MobFox - ios

I followed the documentation to add MobFox ads in my application. For some reason I am getting the error : Could not connect to the server.
func mobFoxAdDidFailToReceiveAdWithError(_ error:Error!) {
print("MobFoxAdDidFailToReceiveAdWithError: ", error.localizedDescription)
}
And it gives:
MobFoxAdDidFailToReceiveAdWithError: Could not connect to the server.
private var mobfoxAd: MobFoxAd!
override func viewDidLoad() {
super.viewDidLoad()
let rect = CGRect(origin: CGPoint(x: 0, y: 200), size: CGSize(width:320, height: 50))
mobfoxAd = MobFoxAd("fe96717d9875b9da4339ea5367eff1ec", withFrame: rect)
mobfoxAd.delegate = self
mobfoxAd.refresh = adRefresh as NSNumber?
self.view.addSubview(mobfoxAd)
}
In my Info.plist file, I have added.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
I don't seem to find the reason.
Thanks.

Turns out the countries where these services are not provided are not mentioned.
If you face this problem, change to another country with VPN. Ads will appear.

Related

Swift Broadcast Replaykit Stop Recording

I have this code for running the BroadCast now I need one Button in App to stop broadcast without going to Notification Centre is that possible.
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
UIScreen.main.addObserver(self, forKeyPath: "captured", options: .new, context: nil)
}
func addRPkitVw() {
let broadcastPickerView = RPSystemBroadcastPickerView(frame: CGRect(x: (holderVw.frame.width / 2) - 19, y: 0, width: 38, height: 38))
holderVw.addSubview(broadcastPickerView)
broadcastPickerView.backgroundColor = .clear
broadcastPickerView.showsMicrophoneButton = true
}
I'm facing same issue, but have you tried with finishBroadcastWithError in RPBroadcastSampleHandler. It's temporary solution, cus there is error popup
You have to pass a message to our Extension Whenever you need to stop the recording. Now in your Upload Broadcast Extension when you get the message just call the finishBroadcastWithError function and pass your own error type.
Example:- Recording successfully stoped etc.

Xcode WKWebView (IOS) Wont Load Webpage, White Screen

I have searched for a few hours now and tried many solutions and none seem to work.
I have disabled my AVG web shield, added this to my plist under App transport
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
Code below
let link = URL(string: "https://stackoverflow.com")!
let req = URLRequest(url: link)
webView.navigationDelegate = self
webView.uiDelegate = self
self.view.addSubview(webView)
self.view.bringSubview(toFront: webView)
self.webView!.load(req)
I am extremely confused why any web page does not load
I have tried http and https
I have tired multiple websites, no luck
it just stays on a blank white screen
Your code works in my playground, so something is wrong with how you are creating the web view or the constraints. See example:
import UIKit
import PlaygroundSupport
import WebKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let webView = WKWebView()
view.addSubview(webView)
webView.translatesAutoresizingMaskIntoConstraints = false
webView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
webView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
webView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
let link = URL(string: "https://stackoverflow.com")!
let req = URLRequest(url: link)
webView.load(req)
view.setNeedsLayout()
}
}
PlaygroundPage.current.needsIndefiniteExecution = true
PlaygroundPage.current.liveView = ViewController()
I get this on OSX apps and works for that go to general app settings, sandbox mode turn on and off again. Works every time for me on OSX apps

UILabel shows wrong Localized String

I have a problem with localizing a string through the Localizable.stringdict. I did setup different localization for different sizes of a Test string. See Localizable.stringdict:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Test</key>
<dict>
<key>NSStringVariableWidthRuleType</key>
<dict>
<key>20</key>
<string>test</string>
<key>25</key>
<string>test message</string>
<key>50</key>
<string>This is a test message</string>
</dict>
</dict>
</dict>
</plist>
My ViewController looks like the following:
class ViewController: UIViewController {
#IBOutlet weak var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let string = NSLocalizedString("Test", comment: "This is a test message") as NSString
let widthFormattedString = string.variantFittingPresentationWidth(50) as String
print(widthFormattedString)
label.text = widthFormattedString
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I would like to assign the localized string to a label. The print in my ViewController is printing "This is a test message", but the view is showing "test message". I don't change the text of the label anywhere else. So I wonder why the wrong message is displayed. Can anyone help?
According to the documentation at writing this answer it states that:
Note
Don't call this method when setting user-visible text for standard UIKit controls, such as UILabel. UIKit provides built-in support for adaptive strings, and automatically selects the string width variant appropriate for the current screen size according to the behavior described below.
which seems to confirm what you experience.
The print out you do yourself is correct because it delivers you the string you requested for the value 50:
The print in my ViewController is printing "This is a test message"
Whereas the UILabel gets a the string by the UIKit standard mechanism and appears as:
but the view is showing "test message"
I conclude that you don't need to do it yourself if you use UIKit controls. This is probably helpful for custom controls or other use cases I'm not aware of.

Custom view for Drag and Drop

I have set up my UITableView to use the new Drag and Drop APIs.
if #available(iOS 11, *) {
self.tableView.dragDelegate = self
self.tableView.dropDelegate = self
self.tableView.dragInteractionEnabled = true
navigationController?.navigationBar.prefersLargeTitles = false
}
Now, I implemented the method below to be able to use custom views for the d&d.
#available(iOS 11.0, *)
func dragInteraction(_ interaction: UIDragInteraction, previewForLifting item: UIDragItem, session: UIDragSession) -> UITargetedDragPreview? {
print("Custom Preview method called!")
let test = UITextView.init(frame: CGRect.init(x: 0, y: 0, width: 200, height: 200))
test.text = "sfgshshsfhshshfshsfh"
let dragView = interaction.view!
let dragPoint = session.location(in: dragView)
let target = UIDragPreviewTarget(container: dragView, center: dragPoint)
return UITargetedDragPreview(view: test, parameters:UIDragPreviewParameters(), target:target)
}
However, this method never gets called. I never see the print() or my custom view. Any ideas as to what I'm doing wrong?
You have to set previewProvider property when creating the UIDragItem.
let dragItem = UIDragItem(...)
dragItem.previewProvider = {
print("Custom Preview method called!")
let test = UITextView.init(frame: CGRect.init(x: 0, y: 0, width: 200, height: 200))
test.text = "sfgshshsfhshshfshsfh"
return UIDragPreview(view: test)
}
See: https://developer.apple.com/documentation/uikit/uidragitem/2890972-previewprovider?language=objc
Are you using an iPhone? I am not certain it is currently working for customer UIViewController as of November 25, 2017 based on the following:
I downloaded the Apple sample project for drag-and-drop on an iPad
I added a breakpoint in dragInteraction and confirmed I could reach it
I modified the target to be a universal app (i.e. iPhone, too)
I ran on an iPhone 8 device and did not reach the breakpoint
As further suggestion, there is a property named dragInteractionEnabled for both UITableViewController and UICollectionViewController. For iPhone devices, the property is defaulted to false and, more importantly, the property is not even defined higher in UIViewController.

My app stop in AppDelegate

My app stop in AppDelegate.
I am making an app which can access camera and photo library and I can upload photos in my app.
I run my app in my real iPhone from Xcode,but when I put camera access button & photo library button, my app stopped in a part AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {
and could not move.
In Cornroller,I wrote
import UIKit
class KenshinSendController:UIViewController,
UINavigationControllerDelegate,UIImagePickerControllerDelegate{
let ButtonCamera = 0
let ButtomRead = 1
let ButtonWrite = 2
var imageView:UIImageView = UIImageView()
var btnCamera:UIButton = UIButton(type: .custom)
var btnRead:UIButton = UIButton(type: .custom)
var btnWrite:UIButton = UIButton(type: .custom)
override func viewDidLoad() {
super.viewDidLoad()
imageView.frame = CGRect(x: 150, y: 100, width: 200, height: 200)
imageView.contentMode = .scaleAspectFit
view.addSubview(imageView)
btnCamera.frame = CGRect(x: 0, y: 100, width: 100, height: 100)
btnCamera.setTitle("Camera", for: .normal)
btnCamera.tag = ButtonCamera
btnCamera.addTarget(self, action: #selector(self.onClick(sender:)), for: .touchUpInside)
btnCamera.backgroundColor = UIColor.green
self.view.addSubview(btnCamera)
btnRead.frame = CGRect(x: 0, y: 200, width: 100, height: 100)
btnRead.setTitle("Read", for: .normal)
btnRead.tag = ButtomRead
btnRead.addTarget(self, action: #selector(self.onClick(sender:)), for: .touchUpInside)
btnRead.backgroundColor = UIColor.red
self.view.addSubview(btnRead)
btnWrite.frame = CGRect(x: 0, y: 300, width: 100, height: 100)
btnWrite.setTitle("Write", for: .normal)
btnWrite.tag = ButtonWrite
btnWrite.addTarget(self, action: #selector(self.onClick(sender:)), for: .touchUpInside)
btnWrite.backgroundColor = UIColor.blue
self.view.addSubview(btnWrite)
}
//ボタンクリック時に呼ばれる
#IBAction func ButtonCamera(_ sender: Any) {
}
#IBAction func ButtonRead(_ sender: Any) {
}
func onClick(sender:UIButton){
if sender.tag == ButtonCamera {
openPicker(sourceType: UIImagePickerControllerSourceType.camera)
}else if sender.tag == ButtomRead {
openPicker(sourceType: UIImagePickerControllerSourceType.photoLibrary)
}
}
//アラートの表示
func showAlert(title: String?, text: String?) {
let alert = UIAlertController(title: title, message: text, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
present(alert, animated: true, completion: nil)
}
func openPicker(sourceType:UIImagePickerControllerSourceType){
if !UIImagePickerController.isSourceTypeAvailable(sourceType){
showAlert(title: nil, text: "利用できません")
return
}
let picker = UIImagePickerController()
picker.sourceType = sourceType
picker.delegate = self
present(picker, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let image = info[UIImagePickerControllerOriginalImage]as! UIImage
imageView.image = image
picker.presentingViewController?.dismiss(animated: true,completion:nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.presentingViewController?.dismiss(animated: true, completion: nil)
}
}
Identity Inspector is like
and AppDelegate.swift is like
import UIKit
import Alamofire
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
Info.plist is like
<plist version="1.0">
<dict>
<key>UILaunchStoryboardName</key>
<string></string>
<key>CFBundleGetInfoString</key>
<string></string>
<key>NSPhotoLibraryUsageDescription</key>
<string>フォトライブラリの使用許可をお願いします</string>
<key>CFBundleDisplayName</key>
<string></string>
<key>NSCameraUsageDescription</key>
<string>カメラの使用許可をお願いします</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
Error message is like Thread 1:signal SIGABRT
I used TabBarController,it is like
Connection Inspector is like
You need to give photo and camera access in info.plist file.
Privacy - Camera Usage Description
Privacy - Photo Library Usage Description
The following answers about iOS 10 will only affect the app's review process and will build and run without errors, so adding these will change nothing in a sense of the app's ability to work:
Privacy - Camera Usage Description: purpose of your app using camera
Privacy - Photo Library Usage Description: purpose of your app using Photo
The issue you are experiencing is usually due to a broken reference your storyboard. You may have changed an outlet name or an IBAction method.
You can check this by selecting the view controller in the storyboard and looking for a ! next to any references. If there is a !, click the X to delete the reference.
See attached image (look at down arrow)
You can also look in the code for an empty circle next to your outlets or actions.
I tested your code, and it's perfect, there is no error in your code.
It seems, you have a wrong link with Interface Builder element in your storyboard. Reason for this kind of error is, wrong link (attachment) of interface builder in storyboard with your view controller.
Please check your initial storyboard & especially initial view controller, its attachment with connection inspector & Identity inspector.
Identity Inspector: Your view controller is properly integrated with current project or not.
Connection inspector: You don't have any wrong link of interface builder.
Share here snapshot of your initial storybaord & view controller also, with identity inspector and connection inspector.
Edit: According to your current snap shot, you may have used Tabbar controller as initial view controller (and two connections are incoming for current view controller you have shared.) but not shared information about tabbar controller here. Share complete snapshot (and source code) of your story board to get exact resolution.
From iOS 10, you have to add privacy descriptions in your info.plist file unless your app will crash when request permission. In your case, you must add:
Privacy - Camera Usage Description : purpose of your app using camera
Privacy - Photo Library Usage Description : purpose of your app using Photo

Resources