Determining if Facebook app is installed from Unity - ios

We are using the Facebook SDK for Unity (v6.0) and I'd like to now whether there's a way that I can check if the Facebook app is installed on the device.
The reason is an existing bug in the Facebook SDK (see here: bug)
I want to identify this scenario (occurs only when the FB app is installed), and react accordingly.

"In order to use a native plugin you firstly need to write functions
in a C-based language to access whatever features you need and compile
them into a library. In Unity, you will also need to create a C#
script which calls functions in the native library."
from http://docs.unity3d.com/Manual/NativePlugins.html
So, basically you need to write your code in Objective-C and provide the communication between the Unity and the Native Code.
The code that you need to implement for checking Facebook APP is;
(void) checkFacebookApp
{
if ([[UIApplication sharedApplication] canOpenURL:[NSURLURLWithString:#"fb://"]])
{
return true;
}
}
However you need some communication between the Unity and Xcode project. So;
class SomeScript : MonoBehaviour {
#if UNITY_IPHONE || UNITY_XBOX360
// On iOS and Xbox 360 plugins are statically linked into
// the executable, so we have to use __Internal as the
// library name.
[DllImport ("__Internal")]
#else
// Other platforms load plugins dynamically, so pass the name
// of the plugin's dynamic library.
[DllImport ("PluginName")]
#endif
private static extern float checkFacebookApp ();
void Awake () {
// Calls the FooPluginFunction inside the plugin
// And prints 5 to the console
bool check = checkFacebookApp ();
}
}

Related

Access Unity 3d UI component like Panel/Image as a view in Objective C code

I have a certain task where i want to pass a UIView to one of the SDK's in my iOS project.
Now, my project is a simple 2D game build in Unity 3d. I want to send the Panel in my Canvas to that SDK as UIView.
I am aware of iOS and Unity communication. It happens using as Char*.
I am not sure how should i access that GameObject Panel in my iOS code as UIView. I will be very thankful if i receive any help on this.
Above is one of solution that you can access from ios interface but before see this, read https://docs.unity3d.com/Manual/PluginsForIOS.html. it will help to understand how unity and native code can communicate.
iOS: test.mm
#import "Unity/UnityInterface.h"
...
...
-(void)SendMessage
{
UnitySendMessage("MessageGameCommunicator", "Receiver", [message UTF8String]);
}
Unity: Commnicator.cs, MessageGameCommunicator (GameObject name)
public class Commnicator : MonoBehaviour
{
public static void Receiver(string message)
{
// ...
// Do something.
}
}
After Unity interface get message from ios, you can implement whatever you want.

passing values from unity 3D to objective c file

My app has two windows. First one is unity 3D exported to ios which uses vuforia kit for doing augmnted reality. Second is native xcode files. I need to pass a string value from unity to native objective c file because I need to display some values based on that. I'm using xcode 7 and unity 5. Please help me understand how to do it. Thanks in advance.
This can be done with the native plugin support in Unity. You need to import the native method into a class and call it via another method. You can find more documentation on it here: http://docs.unity3d.com/Manual/NativePlugins.html
Here is a really simple code example that should fit your needs.
The C# class:
using System.Runtime.InteropServices;
public static class SomeScript
{
[DllImport("__Internal")]
private static extern void _NativeMethodName(string stringValue);
public static void PassStringValue(string stringValue)
{
_NativeMethodName(stringValue);
}
}
And the native plugin code:
extern "C" {
void _NativeMethodName(const char* stringValue)
{
NSLog(#"Passed string value: %s", stringValue);
}
}

How to prevent Screen lock ios with Qt

I want to develop an app in Qt for iOS that contains a map. During the use, the screen lock of the phone should be disabled.
But I can't find any solution how to prevent the screen lock in iOS using Qt.
How can be done that?
You must use the native iOS api. You can compile ObjC++ code directly with the clang compiler in your Qt application.
So you can mix .cpp and .mm (ObjC++) files. QtCreator and qmake support this via the OBJECTIVE_SOURCES keyword.
In a yourclass.mm implementation:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
void YourClass::setTimerDisabled() {
[[UIApplication sharedApplication] setIdleTimerDisabled: YES]
}
yourclass.h:
class YourClass
{
public:
void setTimerDisabled()
}
Now you can call from anywhere in your Qt-app:
YourClass yc;
yc.setTimerDisbabled();
In your project file (.pro), if you only want this file on iOS:
ios {
OBJECTIVE_SOURCES += \
yourclass.mm \
}
And if you only want specified code on a single platform, use preprocessor commands in your source and header files like this:
#if defined(Q_OS_IOS)
// iOs stuff
#elsif defined(Q_OS_ANDROID)
//Android stuff ...
#else
//Other stuff ...
#endif

Write Unity IOS plugin in Swift code

Is it possible to write unity IOS plugin in Swift?
I already have a working swift framework and want to use it as a plugin in Unity
I saw some places which say it can only be done on Objective-c but is there a workaround for swift?
How to call Unity methods
Unity interface functions are defined in UnityInterface.h in Xcode project built by Unity. This header file is imported in UnitySwift-Bridging-Header.h, so you can call the functions directly in your Swift codes.
To call Unity methods, use UnitySendMessage function like below:
// Example.swift
import Foundation
class Example : NSObject {
static func callUnityMethod(_ message: String) {
// Call a method on a specified GameObject.
UnitySendMessage("CallbackTarget", "OnCallFromSwift", message)
}
}
How to access Swift classes from Unity
Step 1: Create your Swift classes.
// Example.swift
import Foundation
class Example : NSObject {
static func swiftMethod(_ message: String) {
print("\(#function) is called with message: \(message)")
}
}
Step 2: Include "unityswift-Swift.h" and define C functions to wrap Swift classes in .mm file (Objective-C++).
// Example.mm
#import <Foundation/Foundation.h>
#import "unityswift-Swift.h" // Required
// This header file is generated automatically when Xcode build runs.
extern "C" {
void _ex_callSwiftMethod(const char *message) {
// You can access Swift classes directly here.
[Example swiftMethod:[NSString stringWithUTF8String:message]];
}
}
Step 3: Create interface class to call exported C functions from C#.
// Example.cs
using System.Runtime.InteropServices;
public class Example {
#if UNITY_IOS && !UNITY_EDITOR
[DllImport("__Internal")]
private static extern void _ex_callSwiftMethod(string message);
#endif
// Use this method to call Example.swiftMethod() in Example.swift
// from other C# classes.
public static void CallSwiftMethod(string message) {
#if UNITY_IOS && !UNITY_EDITOR
_ex_callSwiftMethod(message);
#endif
}
}
Step 4: Call the method from your C# code.
Example.CallSwiftMethod("Hello, Swift!");
The file names of UnitySwift-Bridging-Header.h and unityswift-Swift.h are defined in "Objective-C Bridging Header" entry and "Objective-C Generated Interface Header Name" entry in Build Settings. These settings and other settings about Swift compiler are set automatically by PostProcesser when the Unity build runs.
Requirements
iOS 7 or later
Compatibility
Unity 5.3.5f1 Xcode 7.3.1
As top-level Swift is simply not accessible from Unity, the "workaround" for Swift is to write an Objective-C wrapper class around it, and access that.
Depending on the amount and complexity of your Swift code that might still be the most optimal approach.

How to intercept adding calls to call history in iOS?

I'm developing a tweak for jailbroken iPhones. I'm trying to intercept the process of a call being added to the call history. With a little bit search I found CTCallHistoryStoreAddCall function in CoreTelephony framework found here. When I try to use it I get an error:
Undefined symbols for architecture armv7: "_CTCallHistoryStoreAddCall"
I linked the CoreTelephony framework and the way I used it in my code was:
typedef struct __CTCall * CTCallRef;
extern "C" void CTCallHistoryStoreAddCall(CTCallRef call);
I guess that means this function does not exist anymore or if it does I'm not using it in the correct way.
How can I find the right function that is responsible for adding an incoming phone call to the call history?
Thanks in advanced.
I'm using iOSOpenDev on Xcode 5.
There is no such function. At least in iOS7.
I've posted solution for iOS7 here Hide a phone call completely in iOS (jailbreak device)
Here is the code:
//Private API from CoreTelephony.framework
void CTCallDeleteFromCallHistory(CTCallRef call);
%hook PHRecentCall
-(id)initWithCTCall:(CTCallRef)call
{
if (IsCallShouldBeDeleted(call) == YES)
{
//Delete call from call history
CTCallDeleteFromCallHistory(call);
//Update MobilePhone app UI
id PHRecentsViewController = [[[[[UIApplication sharedApplication] delegate] rootViewController] tabBarViewController] recentsViewController];
if ([PHRecentsViewController isViewLoaded])
{
[PHRecentsViewController resetCachedIndexes];
[PHRecentsViewController _reloadTableViewAndNavigationBar];
}
//Try uncommenting this, may be it will work. Should make the code faster.
//return nil;
}
return %orig;
}
%end
Tweak hooks class inside MobilePhone app so bundle filter is com.apple.mobilephone.
IsCallShouldBeDeleted is pseudo function that determines whether a call should be deleted. You can remove it or implement your own. It's there just to make the code more clear.
On iOS6 class names are different but code is exactly the same - Apple just renamed the classes. I use that solution since iOS4. Also on iOS4 it requires a bit more code as there was no CTCallDeleteFromCallHistory function.
You are encountering this error because the CoreTelephony framework is not being linked to your program. To fix this, add the following to your makefile:
PROJECT_NAME_PRIVATE_FRAMEWORKS = CoreTelephony
Note that you have to replace PROJECT_NAME with your own project's name.

Resources