About the callback of SKStoreReviewController.requestReview()












4















If the review popup initiated from a view controller shows up, there isn't a way to switch the window focus back to the view controller when the popup is dismissed due to lack of callback function of SKStoreReviewController.requestReview().



I would like to make a call to becomeFirstResponder() when the review popup is dismissed. Any idea?



Is there a way to extend the SKStoreReviewController and add a callback somehow?










share|improve this question




















  • 1





    not sure if this will help you stackoverflow.com/questions/43745157/…

    – a4arpan
    Jan 14 at 16:12
















4















If the review popup initiated from a view controller shows up, there isn't a way to switch the window focus back to the view controller when the popup is dismissed due to lack of callback function of SKStoreReviewController.requestReview().



I would like to make a call to becomeFirstResponder() when the review popup is dismissed. Any idea?



Is there a way to extend the SKStoreReviewController and add a callback somehow?










share|improve this question




















  • 1





    not sure if this will help you stackoverflow.com/questions/43745157/…

    – a4arpan
    Jan 14 at 16:12














4












4








4








If the review popup initiated from a view controller shows up, there isn't a way to switch the window focus back to the view controller when the popup is dismissed due to lack of callback function of SKStoreReviewController.requestReview().



I would like to make a call to becomeFirstResponder() when the review popup is dismissed. Any idea?



Is there a way to extend the SKStoreReviewController and add a callback somehow?










share|improve this question
















If the review popup initiated from a view controller shows up, there isn't a way to switch the window focus back to the view controller when the popup is dismissed due to lack of callback function of SKStoreReviewController.requestReview().



I would like to make a call to becomeFirstResponder() when the review popup is dismissed. Any idea?



Is there a way to extend the SKStoreReviewController and add a callback somehow?







swift becomefirstresponder skstorereviewcontroller






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 14 at 14:11







zs2020

















asked Jan 2 at 15:19









zs2020zs2020

45.2k22132194




45.2k22132194








  • 1





    not sure if this will help you stackoverflow.com/questions/43745157/…

    – a4arpan
    Jan 14 at 16:12














  • 1





    not sure if this will help you stackoverflow.com/questions/43745157/…

    – a4arpan
    Jan 14 at 16:12








1




1





not sure if this will help you stackoverflow.com/questions/43745157/…

– a4arpan
Jan 14 at 16:12





not sure if this will help you stackoverflow.com/questions/43745157/…

– a4arpan
Jan 14 at 16:12












1 Answer
1






active

oldest

votes


















0





+100









Warning this will probably break at some point.



Step 1: add this code to your didFinishLaunchingWithOptions



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let windowClass: AnyClass = UIWindow.self

let originalSelector: Selector = #selector(setter: UIWindow.windowLevel)
let swizzledSelector: Selector = #selector(UIWindow.setWindowLevel_startMonitor(_:))

let originalMethod = class_getInstanceMethod(windowClass, originalSelector)
let swizzledMethod = class_getInstanceMethod(windowClass, swizzledSelector)

let didAddMethod = class_addMethod(windowClass, originalSelector, method_getImplementation(swizzledMethod!), method_getTypeEncoding(swizzledMethod!))

if didAddMethod {
class_replaceMethod(windowClass, swizzledSelector, method_getImplementation(originalMethod!), method_getTypeEncoding(originalMethod!))
} else {
method_exchangeImplementations(originalMethod!, swizzledMethod!)
}

return true
}


Step 2: add this class



class MonitorObject: NSObject {
weak var owner: UIWindow?

init(_ owner: UIWindow?) {
super.init()
self.owner = owner
NotificationCenter.default.post(name: UIWindow.didBecomeVisibleNotification, object: self)
}

deinit {
NotificationCenter.default.post(name: UIWindow.didBecomeHiddenNotification, object: self)
}
}


Step 3: Add this UIWindow extension



private var monitorObjectKey = "monitorKey"
private var partialDescForStoreReviewWindow = "SKStore"

extension UIWindow {
// MARK: - Method Swizzling
@objc func setWindowLevel_startMonitor(_ level: Int) {
setWindowLevel_startMonitor(level)

if description.contains(partialDescForStoreReviewWindow) {
let monObj = MonitorObject(self)
objc_setAssociatedObject(self, &monitorObjectKey, monObj, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}


Step 4: add this to ViewDidLoad of your controller where you want this



override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
NotificationCenter.default.addObserver(self, selector: #selector(windowDidBecomeHiddenNotification(_:)), name: UIWindow.didBecomeHiddenNotification, object: nil)
}


Step 5: add the callback for the notification and check that the associated object is a match



@objc func windowDidBecomeHiddenNotification(_ notification: Notification?) {
if notification?.object is MonitorObject {
print("hello")
}
}


Now when a review dialog is closed the notification is triggered and 'print("hello") will be called.






share|improve this answer
























  • Probably because it's considered pretty hacky code, and that it could be cleaned a bit more, or that fact I didn't explain it very well.

    – Dylan
    Jan 16 at 0:02













  • That's fine. I don't think there exists unhacky code coz Apple documentation doesn't say anything about the call back. Thx for the effort!

    – zs2020
    Jan 16 at 0:08











  • Yeah hope they can fix it in the future

    – Dylan
    Jan 16 at 0:11











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008845%2fabout-the-callback-of-skstorereviewcontroller-requestreview%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0





+100









Warning this will probably break at some point.



Step 1: add this code to your didFinishLaunchingWithOptions



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let windowClass: AnyClass = UIWindow.self

let originalSelector: Selector = #selector(setter: UIWindow.windowLevel)
let swizzledSelector: Selector = #selector(UIWindow.setWindowLevel_startMonitor(_:))

let originalMethod = class_getInstanceMethod(windowClass, originalSelector)
let swizzledMethod = class_getInstanceMethod(windowClass, swizzledSelector)

let didAddMethod = class_addMethod(windowClass, originalSelector, method_getImplementation(swizzledMethod!), method_getTypeEncoding(swizzledMethod!))

if didAddMethod {
class_replaceMethod(windowClass, swizzledSelector, method_getImplementation(originalMethod!), method_getTypeEncoding(originalMethod!))
} else {
method_exchangeImplementations(originalMethod!, swizzledMethod!)
}

return true
}


Step 2: add this class



class MonitorObject: NSObject {
weak var owner: UIWindow?

init(_ owner: UIWindow?) {
super.init()
self.owner = owner
NotificationCenter.default.post(name: UIWindow.didBecomeVisibleNotification, object: self)
}

deinit {
NotificationCenter.default.post(name: UIWindow.didBecomeHiddenNotification, object: self)
}
}


Step 3: Add this UIWindow extension



private var monitorObjectKey = "monitorKey"
private var partialDescForStoreReviewWindow = "SKStore"

extension UIWindow {
// MARK: - Method Swizzling
@objc func setWindowLevel_startMonitor(_ level: Int) {
setWindowLevel_startMonitor(level)

if description.contains(partialDescForStoreReviewWindow) {
let monObj = MonitorObject(self)
objc_setAssociatedObject(self, &monitorObjectKey, monObj, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}


Step 4: add this to ViewDidLoad of your controller where you want this



override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
NotificationCenter.default.addObserver(self, selector: #selector(windowDidBecomeHiddenNotification(_:)), name: UIWindow.didBecomeHiddenNotification, object: nil)
}


Step 5: add the callback for the notification and check that the associated object is a match



@objc func windowDidBecomeHiddenNotification(_ notification: Notification?) {
if notification?.object is MonitorObject {
print("hello")
}
}


Now when a review dialog is closed the notification is triggered and 'print("hello") will be called.






share|improve this answer
























  • Probably because it's considered pretty hacky code, and that it could be cleaned a bit more, or that fact I didn't explain it very well.

    – Dylan
    Jan 16 at 0:02













  • That's fine. I don't think there exists unhacky code coz Apple documentation doesn't say anything about the call back. Thx for the effort!

    – zs2020
    Jan 16 at 0:08











  • Yeah hope they can fix it in the future

    – Dylan
    Jan 16 at 0:11
















0





+100









Warning this will probably break at some point.



Step 1: add this code to your didFinishLaunchingWithOptions



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let windowClass: AnyClass = UIWindow.self

let originalSelector: Selector = #selector(setter: UIWindow.windowLevel)
let swizzledSelector: Selector = #selector(UIWindow.setWindowLevel_startMonitor(_:))

let originalMethod = class_getInstanceMethod(windowClass, originalSelector)
let swizzledMethod = class_getInstanceMethod(windowClass, swizzledSelector)

let didAddMethod = class_addMethod(windowClass, originalSelector, method_getImplementation(swizzledMethod!), method_getTypeEncoding(swizzledMethod!))

if didAddMethod {
class_replaceMethod(windowClass, swizzledSelector, method_getImplementation(originalMethod!), method_getTypeEncoding(originalMethod!))
} else {
method_exchangeImplementations(originalMethod!, swizzledMethod!)
}

return true
}


Step 2: add this class



class MonitorObject: NSObject {
weak var owner: UIWindow?

init(_ owner: UIWindow?) {
super.init()
self.owner = owner
NotificationCenter.default.post(name: UIWindow.didBecomeVisibleNotification, object: self)
}

deinit {
NotificationCenter.default.post(name: UIWindow.didBecomeHiddenNotification, object: self)
}
}


Step 3: Add this UIWindow extension



private var monitorObjectKey = "monitorKey"
private var partialDescForStoreReviewWindow = "SKStore"

extension UIWindow {
// MARK: - Method Swizzling
@objc func setWindowLevel_startMonitor(_ level: Int) {
setWindowLevel_startMonitor(level)

if description.contains(partialDescForStoreReviewWindow) {
let monObj = MonitorObject(self)
objc_setAssociatedObject(self, &monitorObjectKey, monObj, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}


Step 4: add this to ViewDidLoad of your controller where you want this



override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
NotificationCenter.default.addObserver(self, selector: #selector(windowDidBecomeHiddenNotification(_:)), name: UIWindow.didBecomeHiddenNotification, object: nil)
}


Step 5: add the callback for the notification and check that the associated object is a match



@objc func windowDidBecomeHiddenNotification(_ notification: Notification?) {
if notification?.object is MonitorObject {
print("hello")
}
}


Now when a review dialog is closed the notification is triggered and 'print("hello") will be called.






share|improve this answer
























  • Probably because it's considered pretty hacky code, and that it could be cleaned a bit more, or that fact I didn't explain it very well.

    – Dylan
    Jan 16 at 0:02













  • That's fine. I don't think there exists unhacky code coz Apple documentation doesn't say anything about the call back. Thx for the effort!

    – zs2020
    Jan 16 at 0:08











  • Yeah hope they can fix it in the future

    – Dylan
    Jan 16 at 0:11














0





+100







0





+100



0




+100





Warning this will probably break at some point.



Step 1: add this code to your didFinishLaunchingWithOptions



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let windowClass: AnyClass = UIWindow.self

let originalSelector: Selector = #selector(setter: UIWindow.windowLevel)
let swizzledSelector: Selector = #selector(UIWindow.setWindowLevel_startMonitor(_:))

let originalMethod = class_getInstanceMethod(windowClass, originalSelector)
let swizzledMethod = class_getInstanceMethod(windowClass, swizzledSelector)

let didAddMethod = class_addMethod(windowClass, originalSelector, method_getImplementation(swizzledMethod!), method_getTypeEncoding(swizzledMethod!))

if didAddMethod {
class_replaceMethod(windowClass, swizzledSelector, method_getImplementation(originalMethod!), method_getTypeEncoding(originalMethod!))
} else {
method_exchangeImplementations(originalMethod!, swizzledMethod!)
}

return true
}


Step 2: add this class



class MonitorObject: NSObject {
weak var owner: UIWindow?

init(_ owner: UIWindow?) {
super.init()
self.owner = owner
NotificationCenter.default.post(name: UIWindow.didBecomeVisibleNotification, object: self)
}

deinit {
NotificationCenter.default.post(name: UIWindow.didBecomeHiddenNotification, object: self)
}
}


Step 3: Add this UIWindow extension



private var monitorObjectKey = "monitorKey"
private var partialDescForStoreReviewWindow = "SKStore"

extension UIWindow {
// MARK: - Method Swizzling
@objc func setWindowLevel_startMonitor(_ level: Int) {
setWindowLevel_startMonitor(level)

if description.contains(partialDescForStoreReviewWindow) {
let monObj = MonitorObject(self)
objc_setAssociatedObject(self, &monitorObjectKey, monObj, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}


Step 4: add this to ViewDidLoad of your controller where you want this



override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
NotificationCenter.default.addObserver(self, selector: #selector(windowDidBecomeHiddenNotification(_:)), name: UIWindow.didBecomeHiddenNotification, object: nil)
}


Step 5: add the callback for the notification and check that the associated object is a match



@objc func windowDidBecomeHiddenNotification(_ notification: Notification?) {
if notification?.object is MonitorObject {
print("hello")
}
}


Now when a review dialog is closed the notification is triggered and 'print("hello") will be called.






share|improve this answer













Warning this will probably break at some point.



Step 1: add this code to your didFinishLaunchingWithOptions



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let windowClass: AnyClass = UIWindow.self

let originalSelector: Selector = #selector(setter: UIWindow.windowLevel)
let swizzledSelector: Selector = #selector(UIWindow.setWindowLevel_startMonitor(_:))

let originalMethod = class_getInstanceMethod(windowClass, originalSelector)
let swizzledMethod = class_getInstanceMethod(windowClass, swizzledSelector)

let didAddMethod = class_addMethod(windowClass, originalSelector, method_getImplementation(swizzledMethod!), method_getTypeEncoding(swizzledMethod!))

if didAddMethod {
class_replaceMethod(windowClass, swizzledSelector, method_getImplementation(originalMethod!), method_getTypeEncoding(originalMethod!))
} else {
method_exchangeImplementations(originalMethod!, swizzledMethod!)
}

return true
}


Step 2: add this class



class MonitorObject: NSObject {
weak var owner: UIWindow?

init(_ owner: UIWindow?) {
super.init()
self.owner = owner
NotificationCenter.default.post(name: UIWindow.didBecomeVisibleNotification, object: self)
}

deinit {
NotificationCenter.default.post(name: UIWindow.didBecomeHiddenNotification, object: self)
}
}


Step 3: Add this UIWindow extension



private var monitorObjectKey = "monitorKey"
private var partialDescForStoreReviewWindow = "SKStore"

extension UIWindow {
// MARK: - Method Swizzling
@objc func setWindowLevel_startMonitor(_ level: Int) {
setWindowLevel_startMonitor(level)

if description.contains(partialDescForStoreReviewWindow) {
let monObj = MonitorObject(self)
objc_setAssociatedObject(self, &monitorObjectKey, monObj, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}


Step 4: add this to ViewDidLoad of your controller where you want this



override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
NotificationCenter.default.addObserver(self, selector: #selector(windowDidBecomeHiddenNotification(_:)), name: UIWindow.didBecomeHiddenNotification, object: nil)
}


Step 5: add the callback for the notification and check that the associated object is a match



@objc func windowDidBecomeHiddenNotification(_ notification: Notification?) {
if notification?.object is MonitorObject {
print("hello")
}
}


Now when a review dialog is closed the notification is triggered and 'print("hello") will be called.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 15 at 22:10









DylanDylan

467918




467918













  • Probably because it's considered pretty hacky code, and that it could be cleaned a bit more, or that fact I didn't explain it very well.

    – Dylan
    Jan 16 at 0:02













  • That's fine. I don't think there exists unhacky code coz Apple documentation doesn't say anything about the call back. Thx for the effort!

    – zs2020
    Jan 16 at 0:08











  • Yeah hope they can fix it in the future

    – Dylan
    Jan 16 at 0:11



















  • Probably because it's considered pretty hacky code, and that it could be cleaned a bit more, or that fact I didn't explain it very well.

    – Dylan
    Jan 16 at 0:02













  • That's fine. I don't think there exists unhacky code coz Apple documentation doesn't say anything about the call back. Thx for the effort!

    – zs2020
    Jan 16 at 0:08











  • Yeah hope they can fix it in the future

    – Dylan
    Jan 16 at 0:11

















Probably because it's considered pretty hacky code, and that it could be cleaned a bit more, or that fact I didn't explain it very well.

– Dylan
Jan 16 at 0:02







Probably because it's considered pretty hacky code, and that it could be cleaned a bit more, or that fact I didn't explain it very well.

– Dylan
Jan 16 at 0:02















That's fine. I don't think there exists unhacky code coz Apple documentation doesn't say anything about the call back. Thx for the effort!

– zs2020
Jan 16 at 0:08





That's fine. I don't think there exists unhacky code coz Apple documentation doesn't say anything about the call back. Thx for the effort!

– zs2020
Jan 16 at 0:08













Yeah hope they can fix it in the future

– Dylan
Jan 16 at 0:11





Yeah hope they can fix it in the future

– Dylan
Jan 16 at 0:11




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008845%2fabout-the-callback-of-skstorereviewcontroller-requestreview%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith