Skip to content

Commit

Permalink
update to swift 4
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzhuie committed Oct 9, 2018
1 parent 8b6cd89 commit 925bd30
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 149 deletions.
10 changes: 9 additions & 1 deletion Complete Example/SpaceAdsSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,13 @@
1FE2BDC41BE7E4DF0063D636 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Unity;
TargetAttributes = {
1FE2BDCB1BE7E4DF0063D636 = {
CreatedOnToolsVersion = 7.0.1;
DevelopmentTeam = ZMVW3AW7K7;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -289,8 +290,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -334,8 +337,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -354,6 +359,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -377,6 +383,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_INCLUDE_PATHS = "";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -398,6 +405,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_INCLUDE_PATHS = "";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
12 changes: 6 additions & 6 deletions Complete Example/SpaceAdsSwift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
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 throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
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) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
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) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
20 changes: 10 additions & 10 deletions Complete Example/SpaceAdsSwift/GameViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class GameViewController: UIViewController, UnityAdsDelegate {
super.viewDidLoad()

//initialize Unity Ads
UnityAds.initialize("1003843", delegate: self)
UnityAds.initialize("20721", delegate: self)

spaceScene = SpaceScene(size: view.bounds.size)
planetScene = PlanetScene(size: view.bounds.size)
scene = spaceScene
launchSpriteKitScene(scene)
}

func playAd(placement: String, sender: SKScene) {
func playAd(_ placement: String, sender: SKScene) {
scene = sender
playerIsWatchingRewardedVideo = (placement == "rewardedVideo")
if (UnityAds.isReady(placement)){
Expand All @@ -41,22 +41,22 @@ class GameViewController: UIViewController, UnityAdsDelegate {
}
}

func unityAdsReady(placementId: String) {
func unityAdsReady(_ placementId: String) {

}

func unityAdsDidStart(placementId: String) {
func unityAdsDidStart(_ placementId: String) {

}

func unityAdsDidError(error: UnityAdsError, withMessage message: String) {
func unityAdsDidError(_ error: UnityAdsError, withMessage message: String) {

}

func unityAdsDidFinish(placementId: String, withFinishState state: UnityAdsFinishState) {
if !scene.respondsToSelector(Selector("UnityAdsGetReward")){
func unityAdsDidFinish(_ placementId: String, with state: UnityAdsFinishState) {
if !scene.responds(to: Selector("UnityAdsGetReward")){
print("selector 'UnityAdsGetReward' not available for scene \(scene)")
}else if (state != .Skipped && playerIsWatchingRewardedVideo) {
}else if (state != .skipped && playerIsWatchingRewardedVideo) {
let currentScene = scene as! PlanetScene
currentScene.UnityAdsGetReward()
}
Expand All @@ -65,10 +65,10 @@ class GameViewController: UIViewController, UnityAdsDelegate {
launchSpriteKitScene(scene)
}

func launchSpriteKitScene(scene: SKScene) {
func launchSpriteKitScene(_ scene: SKScene) {
let skView = view as! SKView
skView.ignoresSiblingOrder = true
scene.scaleMode = .ResizeFill
scene.scaleMode = .resizeFill
skView.presentScene(scene)
}
}
Loading

0 comments on commit 925bd30

Please sign in to comment.