查看完整版本: [-- 关于Qt iOS中Qt如何与Obj-c中的UIApplication进行相结合的问题 --]

QTCN开发网 -> Qt移动平台开发 -> 关于Qt iOS中Qt如何与Obj-c中的UIApplication进行相结合的问题 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

toby520 2015-02-06 10:58

关于Qt iOS中Qt如何与Obj-c中的UIApplication进行相结合的问题

最近在研究如何使用第三方的消息推送,这样iOS就得接入iOS的消息推送的SDK到Qt项目中,第三方提供了.a库和.h文件
再研究了一下他们提供的iOS的demo,但是嵌入到Qt项目中 大费周章,还是没有搞定
具体问题和操作如下:
参考这个例子 https://github.com/colede/qt-app-delegate
但是发现代理的应用UI只能触发某几个回调,我想要的是回调

  • (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions
    {
    [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
    // Override point for customization after application launch.
    NSLog(@"DId this launch option happen");
    return YES;
    }
    但是始终没有触发该回调
    无力挣扎,去查阅了Qt iOS源码 发现也有次代理UI,但是没有找到入口

toby520 2015-02-10 10:35
    

彩阳 2015-02-10 13:07
解决了没有?iOS我们全指望居士了。

toby520 2015-02-10 17:42
qt混合obj-c注意的实现
I did my homework … and I solved the problem.
I post here a sketch of the solution:
create at least two files: myNativeWrapperFunctions.h e myNativeWrapperFunctions.mm; The .h file declare C functions that can be called from C++ and in the .mm file they will implemented using objective-C and accessing to the native iOS frameworks
simply add the .h to the HEADERS and .mm to SOURCES into the QMake project
using QMake create the XCode project; XCode knows how to compile .mm files (that’s indicate objective-C that can be mixed with C++)
include the header myNativeWrapperFunctions.h into a C++ source code and call the functions

toby520 2015-02-10 17:55
看了很多资料,估计只能修改Qt iOS源码才可以做到,他封装的qiosapplicationdelegate里面没任何信号发出来,也无法对其进行重写,蛋疼啊
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    Q_UNUSED(application);
    Q_UNUSED(launchOptions);

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.window.rootViewController = [[[QIOSViewController alloc] init] autorelease];

#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_7_0)
    QSysInfo::MacVersion iosVersion = QSysInfo::MacintoshVersion;

    // We prefer to keep the root viewcontroller in fullscreen layout, so that
    // we don't have to compensate for the viewcontroller position. This also
    // gives us the same behavior on iOS 5/6 as on iOS 7, where full screen layout
    // is the only way.
    if (iosVersion < QSysInfo::MV_IOS_7_0)
        self.window.rootViewController.wantsFullScreenLayout = YES;

    // Use translucent statusbar by default on iOS6 iPhones (unless the user changed
    // the default in the Info.plist), so that windows placed under the stausbar are
    // still visible, just like on iOS7.
    if (iosVersion >= QSysInfo::MV_IOS_6_0 && iosVersion < QSysInfo::MV_IOS_7_0
        && [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone
        && [UIApplication sharedApplication].statusBarStyle == UIStatusBarStyleDefault)
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
#endif

    self.window.hidden = NO;

    return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    Q_UNUSED(application);
    Q_UNUSED(sourceApplication);
    Q_UNUSED(annotation);

    if (!QGuiApplication::instance())
        return NO;

    QIOSIntegration *iosIntegration = static_cast<QIOSIntegration *>(QGuiApplicationPrivate::platformIntegration());
    QIOSServices *iosServices = static_cast<QIOSServices *>(iosIntegration->services());

    return iosServices->handleUrl(QUrl::fromNSURL(url));
}

- (void)dealloc
{
    [window release];
    [super dealloc];
}

@end
这个就是我需要重写的

toby520 2015-02-10 18:03
In order to integrate the Facebook SDK into iOS application, some delegates needs to be implemented. One of those, regards the UIApplicationDelegate application:openURL:sourceApplication:annotation. In a fully native iOS application this is not a problem, but in Qt application there is already one delegate, QIOSApplicationDelegate, used by Qt and cannot be specified more than one delegate. At the moment there is a bug opened for solving this issues (QTBUG-38184), and in the meanwhile the only way is to exploit the functionality of Objective-C and do some sort of hacking to implement the delegate into QIOSApplicationDelegate. This sort of hack use the Objective-C categories, and if in your project there is only QtFacebook that do this kind of hack to QIOSApplicationDelegate then all is fine. But, this way to solve the problem may conflict with some other libraries that apply the same hack to solve this issues. Pay attention.

foxgod 2016-01-05 15:58
问个问题,qudpsocket 在ios里面按home键,会10s后就断网吗,因为我用raknet这个网络库在ios里面10s就断网了

toby520 2016-01-06 09:25
foxgod:问个问题,qudpsocket 在ios里面按home键,会10s后就断网吗,因为我用raknet这个网络库在ios里面10s就断网了 (2016-01-05 15:58) 

当然,移动设备在后台很容易断开tcp连接 既网络连接,所以需要推送或者重连机制,但是如果应用在后台,网络是被禁用的

samsonshu 2017-03-29 20:02
楼主,你那个appdelegate入口代理里面的东西搞定了么

samsonshu 2017-03-30 10:39
楼主,看见回下啊,在线等啊

toby520 2017-03-30 11:09
samsonshu:[表情] [表情] 楼主,看见回下啊,在线等啊 (2017-03-30 10:39) 

https://github.com/toby20130333/qtiospush  可以参考我写的这个例子

samsonshu 2017-03-30 15:57
楼主真给你,太谢谢了,已经成功运行。下一步准备去调用其他第三方在QT for ios中运行了。

toby520 2017-03-31 09:02
samsonshu:[表情] [表情] [表情] [表情] 楼主真给你,太谢谢了,已经成功运行。下一步准备去调用其他第三方在QT for ios中运行了。[表情]  (2017-03-30 15:57) 

有空加我签名下的群 交流交流

新手崛起 2017-04-05 17:38
楼主,我看了你前面那个qt的简单demo,执行  [[QtAppDelegate sharedQtAppDelegate] setWindow:appDelegate.window];就会崩溃,注释掉会正常运行,但是不会进入didFinishLaunchingWithOptions,后面有的函数就能进入,你的程序,我暂时没看懂,运行报错,就想问下,你是怎么在原有的那个demo上面改近进入那个didFinish的函数接口的?

新手崛起 2017-04-13 18:03
samsonshu:[表情] [表情] [表情] [表情] 楼主真给你,太谢谢了,已经成功运行。下一步准备去调用其他第三方在QT for ios中运行了。[表情]  (2017-03-30 15:57) 

你好,我想问下你运行楼主的程序有没有进入didFinishLaunchingWithOptions,我运行怎么就没进去过

新手崛起 2017-04-28 10:10
已经解决了,看来还得自己静下心来理解代码


查看完整版本: [-- 关于Qt iOS中Qt如何与Obj-c中的UIApplication进行相结合的问题 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled