IOS - qiosapplicationdelegate.h linking problem in QtCreator
-
wrote on 22 Nov 2015, 22:50 last edited by Vi67
Hello,
I would like to use QIOSApplicationDelegate in my own AppDelegate.m
I'm using Qt Creator to make project. And it doesn't find the type QIOSApplicationDelegate.
I know it comes from qtbase/src/platforms/ios/qiosapplicationdelegate.h, but I don't find it in Qt5.5.1/5.5/ios/include folder.
Do you have an idea how to use this type in my project ?
Thanks for your help
-
wrote on 22 Nov 2015, 23:17 last edited by
The header is missing because it's not intended to be used by developers. As we have no other way to extend the default application delegate, my workaround was to copy its definition in my project and extend it using a category. It works nicely.
myapplicationdelegate.h
#import <UIKit/UIKit.h> @interface QIOSApplicationDelegate : UIResponder <UIApplicationDelegate> @end @interface QIOSApplicationDelegate (MyApplicationDelegate) - (void) someMethod; @end
myapplicationdelegate.m
#include "myapplicationdelegate.h" @implementation QIOSApplicationDelegate (MyApplicationDelegate) -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { // } - (void) someMethod { // } @end
-
wrote on 23 Nov 2015, 13:36 last edited by
It's working fine.
Thank you a lot -
wrote on 23 Nov 2015, 14:08 last edited by
Be careful when overriding the following method:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
This is the only one implemented by QIOSApplicationDelegate, so make sure you call the base implementation using "super".
-
wrote on 23 Nov 2015, 19:08 last edited by
Thanks for the advise.
I'm trying to include Google Cloud Messaging, but I don't know where to put properties from AppDelegate interface.
If I follow the example there . I get some build errors :MyAppDelegate.m:21: error : use of undeclared identifier '_registrationKey' _registrationKey = @"onRegistrationCompleted";
There is the code :
MyAppDelegate.h
#import <ios/Pods/Google/Headers/GGLCloudMessaging/Public/CloudMessaging.h> #import <UIKit/UIKit.h> @interface QIOSApplicationDelegate : UIResponder <UIApplicationDelegate, GGLInstanceIDDelegate, GCMReceiverDelegate> @end @interface QIOSApplicationDelegate (MyAppDelegate) @property(nonatomic, strong) UIWindow *window; @property(nonatomic, readonly, strong) NSString *registrationKey; @property(nonatomic, readonly, strong) NSString *messageKey; @property(nonatomic, readonly, strong) NSString *gcmSenderID; @property(nonatomic, readonly, strong) NSDictionary *registrationOptions; @end
MyAppDelegate.m
#include "MyAppDelegate.h" @interface QIOSApplicationDelegate (MyAppDelegate) @property(nonatomic, strong) void (^registrationHandler)(NSString *registrationToken, NSError *error); @property(nonatomic, assign) BOOL connectedToGCM; @property(nonatomic, strong) NSString* registrationToken; @property(nonatomic, assign) BOOL subscribedToTopic; @end @implementation QIOSApplicationDelegate (MyAppDelegate) // [START register_for_remote_notifications] - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // [START_EXCLUDE] _registrationKey = @"onRegistrationCompleted"; _messageKey = @"onMessageReceived"; ..................
Do you have an idea ?
-
wrote on 23 Nov 2015, 19:28 last edited by
Properties on categories can't be synthesized automatically. You have to provide the get and set methods yourself. Please, take a look at:
-
wrote on 24 Nov 2015, 16:42 last edited by
Thx, now it looks like the builder is ok with this way of synthesizing.
But the linker has some problems, because it may missing a link flag ? There is the trace :Undefined symbols for architecture arm64: "_sqlite3_bind_double", referenced from: ___59-[GMRSqliteStore upsertStatementForRecord:inTableWithName:]_block_invoke350 in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_bind_null", referenced from: ___59-[GMRSqliteStore upsertStatementForRecord:inTableWithName:]_block_invoke350 in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_column_type", referenced from: -[GMRSqliteStore valueAtColumn:forStatement:] in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_column_double", referenced from: -[GMRSqliteStore valueAtColumn:forStatement:] in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_open_v2", referenced from: -[GMRSqliteStore openAndValidateDatabase] in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_column_count", referenced from: -[GMRSqliteStore recordsForQuery:] in libGGLCore.a(GMRSqliteStore.o) -[GMRSqliteStore validateDatabase] in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_clear_bindings", referenced from: -[GMRSqliteStore tableExists:] in libGGLCore.a(GMRSqliteStore.o) -[GMRSqliteStore rowCountForTableWithName:columnName:columnValue:] in libGGLCore.a(GMRSqliteStore.o) -[GMRSqliteStore recordsForQuery:] in libGGLCore.a(GMRSqliteStore.o) "_OBJC_CLASS_$_SKPaymentQueue", referenced from: objc-class-ref in libGGLCore.a(GMRInAppPurchaseTransactionReporter.o) "_sqlite3_column_bytes", referenced from: -[GCMRmq2PersistentStore scanOutgoingRmqMessagesWithHandler:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GMRSqliteStore valueAtColumn:forStatement:] in libGGLCore.a(GMRSqliteStore.o) "_OBJC_CLASS_$_SKProductsRequest", referenced from: objc-class-ref in libGGLCore.a(GMRProductsRequest.o) "_sqlite3_reset", referenced from: -[GMRSqliteStore tableExists:] in libGGLCore.a(GMRSqliteStore.o) -[GMRSqliteStore dropTableWithName:] in libGGLCore.a(GMRSqliteStore.o) -[GMRSqliteStore rowCountForTableWithName:columnName:columnValue:] in libGGLCore.a(GMRSqliteStore.o) -[GMRSqliteStore deleteAllRecordsFromTableWithName:] in libGGLCore.a(GMRSqliteStore.o) -[GMRSqliteStore recordsForQuery:] in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_changes", referenced from: -[GCMRmq2PersistentStore deleteMessagesFromTable:withRmqIds:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore deleteExpiredOrFinishedSyncMessages:] in libGcmLib.a(GCMRmq2PersistentStore.o) "_sqlite3_errmsg", referenced from: -[GCMRmq2PersistentStore saveMessageWithRmqId:tag:data:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore lastErrorMessage] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GMRSqliteStore lastErrorMessage] in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_column_blob", referenced from: -[GCMRmq2PersistentStore scanOutgoingRmqMessagesWithHandler:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GMRSqliteStore valueAtColumn:forStatement:] in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_step", referenced from: -[GCMRmq2PersistentStore saveUnackedS2dMessageWithRmqId:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore saveMessageWithRmqId:tag:data:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore deleteMessagesFromTable:withRmqIds:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore queryHighestRmqId] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore queryLastRmqId] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore updateLastOutgoingRmqId:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore unackedS2dRmqIds] in libGcmLib.a(GCMRmq2PersistentStore.o) ... "_sqlite3_bind_blob", referenced from: -[GCMRmq2PersistentStore saveMessageWithRmqId:tag:data:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) ___59-[GMRSqliteStore upsertStatementForRecord:inTableWithName:]_block_invoke350 in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_column_name", referenced from: -[GMRSqliteStore recordsForQuery:] in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_bind_int", referenced from: -[GCMRmq2PersistentStore saveMessageWithRmqId:tag:data:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore updateLastOutgoingRmqId:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore saveSyncMessageWithRmqID:expirationTime:apnsReceived:mcsReceived:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) "_sqlite3_errcode", referenced from: -[GCMRmq2PersistentStore saveMessageWithRmqId:tag:data:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore deleteExpiredOrFinishedSyncMessages:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore saveSyncMessageWithRmqID:expirationTime:apnsReceived:mcsReceived:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore updateSyncMessageWithRmqID:column:value:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore lastErrorCode] in libGcmLib.a(GCMRmq2PersistentStore.o) "_sqlite3_column_int", referenced from: -[GCMRmq2PersistentStore scanOutgoingRmqMessagesWithHandler:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore querySyncMessageWithRmqID:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GMRSqliteStore rowCountForTableWithName:columnName:columnValue:] in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_prepare_v2", referenced from: -[GCMRmq2PersistentStore saveUnackedS2dMessageWithRmqId:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore saveMessageWithRmqId:tag:data:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore deleteMessagesFromTable:withRmqIds:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore queryHighestRmqId] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore queryLastRmqId] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore updateLastOutgoingRmqId:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore unackedS2dRmqIds] in libGcmLib.a(GCMRmq2PersistentStore.o) ... "_sqlite3_column_int64", referenced from: -[GCMRmq2PersistentStore queryHighestRmqId] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore queryLastRmqId] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore scanOutgoingRmqMessagesWithHandler:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore querySyncMessageWithRmqID:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GMRSqliteStore valueAtColumn:forStatement:] in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_bind_int64", referenced from: -[GCMRmq2PersistentStore saveMessageWithRmqId:tag:data:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore deleteMessagesFromTable:withRmqIds:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore updateLastOutgoingRmqId:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore saveSyncMessageWithRmqID:expirationTime:apnsReceived:mcsReceived:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) ___59-[GMRSqliteStore upsertStatementForRecord:inTableWithName:]_block_invoke350 in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_finalize", referenced from: -[GCMRmq2PersistentStore saveUnackedS2dMessageWithRmqId:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore saveMessageWithRmqId:tag:data:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore deleteMessagesFromTable:withRmqIds:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore queryHighestRmqId] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore queryLastRmqId] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore updateLastOutgoingRmqId:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore unackedS2dRmqIds] in libGcmLib.a(GCMRmq2PersistentStore.o) ... "_sqlite3_column_text", referenced from: -[GCMRmq2PersistentStore unackedS2dRmqIds] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore querySyncMessageWithRmqID:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GMRSqliteStore columnsForTableWithName:] in libGGLCore.a(GMRSqliteStore.o) -[GMRSqliteStore validateDatabase] in libGGLCore.a(GMRSqliteStore.o) -[GMRSqliteStore valueAtColumn:forStatement:] in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_bind_text", referenced from: -[GCMRmq2PersistentStore saveUnackedS2dMessageWithRmqId:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore deleteMessagesFromTable:withRmqIds:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore saveSyncMessageWithRmqID:expirationTime:apnsReceived:mcsReceived:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore updateSyncMessageWithRmqID:column:value:error:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GMRSqliteStore bindToStatement:text:atIndex:] in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_open", referenced from: -[GCMRmq2PersistentStore openDatabase:] in libGcmLib.a(GCMRmq2PersistentStore.o) "_sqlite3_exec", referenced from: -[GCMRmq2PersistentStore createTableWithName:command:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GCMRmq2PersistentStore dropTableWithName:] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GMRSqliteStore beginTransaction] in libGGLCore.a(GMRSqliteStore.o) -[GMRSqliteStore endTransaction] in libGGLCore.a(GMRSqliteStore.o) -[GMRSqliteStore rollbackTransaction] in libGGLCore.a(GMRSqliteStore.o) "_sqlite3_close", referenced from: -[GCMRmq2PersistentStore dealloc] in libGcmLib.a(GCMRmq2PersistentStore.o) -[GMRSqliteStore closeDatabase] in libGGLCore.a(GMRSqliteStore.o) ld: symbol(s) not found for architecture arm64
-
wrote on 24 Nov 2015, 16:44 last edited by
Google Cloud Messaging requires the sqlite library. Add -lsqlite3 to your linker flags.
-
wrote on 24 Nov 2015, 17:18 last edited by
QMAKE_LFLAGS += -lsqlite3
Uhuh :) it worked for _sqlite3 links, but there is still _OBJC_CLASS link.
QMAKE_LFLAGS += -lsqlite3 -ObjC
Then I tried with -ObjC. But I got an other error :
Undefined symbols for architecture arm64:
"_ABMultiValueReplaceLabelAtIndex", referenced from:
-[GSDK_GTMABMutableMultiValue replaceLabelAtIndex:withLabel:] in libGTM_AddressBook.a(GTMABAddressBook.o)
"_ABMultiValueGetPropertyType", referenced from:
-[GSDK_GTMABMultiValue propertyType] in libGTM_AddressBook.a(GTMABAddressBook.o)
...QMAKE_LFLAGS += -lsqlite3 -ObjC -framework
I added -framework. An other error :
ld: framework not found -stdlib=libc++QMAKE_LFLAGS += -lsqlite3 -ObjC -framework -stdlib=libstdc++
With -stdlib=libstdc++, the error is :
ld: framework not found -stdlib=libstdc++ -
wrote on 24 Nov 2015, 17:37 last edited by
It's woking with those linker options :
QMAKE_LFLAGS += -ObjC -lsqlite3 -lz -framework "AddressBook" -framework "AssetsLibrary" -framework "CoreFoundation" -framework "CoreGraphics" -framework "CoreLocation" -framework "CoreMotion" -framework "MessageUI" -framework "SystemConfiguration"
Thx again, Leonardo. I'm nearer from the Notification Push system.
-
wrote on 24 Nov 2015, 17:55 last edited by
If you're just interested in receiving push notifications, I think the InstanceID library would be enough.
-
wrote on 25 Nov 2015, 11:17 last edited by
Do you mean I don't need all of those libraries :
ios/Pods/GGLInstanceID/Libraries/libGGLInstanceIDLib.a \ ios/Pods/Google/Libraries/libGGLCloudMessaging.a \ ios/Pods/Google/Libraries/libGGLCore.a \ ios/Pods/GoogleCloudMessaging/Libraries/libGcmLib.a \ ios/Pods/GoogleInterchangeUtilities/Libraries/libProtocolBuffers.a \ ios/Pods/GoogleIPhoneUtilities/Libraries/libGIP_Reachability.a \ ios/Pods/GoogleNetworkingUtilities/Libraries/libGTMSessionFetcher_core.a \ ios/Pods/GoogleNetworkingUtilities/Libraries/libGTMSessionFetcher_full.a \ ios/Pods/GoogleSymbolUtilities/Libraries/libGSDK_Overload.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_AddressBook.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_core.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_DebugUtils.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_GTMURLBuilder.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_iPhone.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_KVO.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_NSData+zlib.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_NSDictionary+URLArguments.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_NSScannerJSON.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_NSStringHTML.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_NSStringXML.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_Regex.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_RoundedRectPath.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_StringEncoding.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_SystemVersion.a \ ios/Pods/GoogleUtilities/Libraries/libGTM_UIFont+LineHeight.a \ ios/Pods/GoogleUtilities/Libraries/libGTMStackTrace.a
I have a bug about including GoogleService-Info.plist, I'm not sure about the right way to do.
In the .pro file, I have this :QMAKE_BUNDLE_DATA += ios/GoogleService-Info.plist QMAKE_INFO_PLIST = ios/Info.plist
The GoogleService-Info.plist should be ok, I already tested it in the example project of Google.
There is this error during execution :Clearing previous value from *error Could not locate configuration file: 'GoogleService-Info.plist'. Shared configuration dictionary was nil Could not locate configuration file: 'GoogleService-Info.plist'. *** Assertion failure in -[QIOSApplicationDelegate application:didFinishLaunchingWithOptions:], /Users/vi/myproject/ios/src/MyAppDelegate.m:74 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error configuring Google services: Error Domain=com.google.greenhouse Code=-100 "Unable to configure GGL." UserInfo={NSLocalizedRecoverySuggestion=Check formatting and location of GoogleService-Info.plist., NSLocalizedDescription=Unable to configure GGL., NSLocalizedFailureReason=Unable to parse supplied GoogleService-Info.plist. See log for details.}' *** First throw call stack: (0x18537cf48 0x199f2ff80 0x18537ce18 0x186270a1c 0x1000ccea8 0x18a985324 0x18abb3acc 0x18abb7e0c 0x18abb4f50 0x18f19b7c4 0x18f19bb44 0x185334544 0x185333fd8 0x185331cd8 0x185260ca0 0x18a97e1c8 0x18a978ffc 0x10016f794 0x19a77e8b8) libc++abi.dylib: terminating with uncaught exception of type NSException
-
wrote on 25 Nov 2015, 13:41 last edited by
I mean you don't need to have the GCM service and library. I couldn't test it yet, but I have a similar app, and their guide for iOS suggests that once you have a registration token, you're ready to receive push notifications.
Maybe you should give it a try and test it for us. I think that the GCM library is useful for sending and receiving real time messages, like in messaging apps. But other than that, if your application is not in foreground, Google is forced to use the same push delivery system any of us would have to use. And for that the token is enough. No need for a GCM service or GoogleService-Info.plist. Here are the flags I'm using:
-ObjC -framework AddressBook -lGGLInstanceIDLib -lGTM_iPhone -lGTM_core -lGTM_UIFont+LineHeight -lGTM_SystemVersion -lGTM_StringEncoding -lGTM_RoundedRectPath -lGTM_Regex -lGTM_NSStringXML -lGTM_NSStringHTML -lGTM_NSScannerJSON -lGTM_NSDictionary+URLArguments -lGTM_NSData+zlib -lGTM_KVO -lGTM_GTMURLBuilder -lGTM_DebugUtils -lGTM_AddressBook -lGTMStackTrace -lGTMSessionFetcher_full -lGTMSessionFetcher_core -lGSDK_Overload
Using these libraries:
GGLInstanceID, GoogleNetworkingUtilities, GoogleUtilities, GoogleSymbolUtilities
-
wrote on 25 Nov 2015, 17:00 last edited by
Thx, I'm going to try that. Sounds good idea.
-
wrote on 25 Nov 2015, 23:04 last edited by
I've tried something, but I have a bug during the execution of didRegisterForRemoteNotificationsWithDeviceToken function :
-[QIOSApplicationDelegate gcmSenderID]: unrecognized selector sent to instance 0x13e524860 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[QIOSApplicationDelegate gcmSenderID]: unrecognized selector sent to instance 0x13e524860'
There is the function :
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { GGLInstanceIDConfig *instanceIDConfig = [GGLInstanceIDConfig defaultConfig]; instanceIDConfig.delegate = self; [[GGLInstanceID sharedInstance] startWithConfig:instanceIDConfig]; self.registrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken, kGGLInstanceIDAPNSServerTypeSandboxOption:@YES}; self.gcmSenderID = @"MYSENDERID"; [[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity:self.gcmSenderID scope:kGGLInstanceIDScopeGCM options:self.registrationOptions handler:self.registrationHandler]; }
There is the didFinishLaunchingWithOptions function :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.registrationKey = @"onRegistrationCompleted"; self.gcmSenderID = @"MYSENDERID"; // Register for remote notifications if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) { // iOS 7.1 or earlier UIRemoteNotificationType allNotificationTypes = (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge); [application registerForRemoteNotificationTypes:allNotificationTypes]; } else { // iOS 8 or later UIUserNotificationType allNotificationTypes = (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } __weak typeof(self) weakSelf = self; // Handler for registration token request self.registrationHandler = ^(NSString *registrationToken, NSError *error) { if (registrationToken != nil) { weakSelf.registrationToken = registrationToken; NSLog(@"Registration Token: %@", registrationToken); //[weakSelf subscribeToTopic]; NSDictionary *userInfo = @{@"registrationToken":registrationToken}; [[NSNotificationCenter defaultCenter] postNotificationName:weakSelf.registrationKey object:nil userInfo:userInfo]; } else { NSLog(@"Registration to GCM failed with error: %@", error.localizedDescription); NSDictionary *userInfo = @{@"error":error.localizedDescription}; [[NSNotificationCenter defaultCenter] postNotificationName:weakSelf.registrationKey object:nil userInfo:userInfo]; } }; return YES; }
-
wrote on 26 Nov 2015, 10:42 last edited by
According to this stackoverflow post, I should use the gstatic version of GCM.
I don't have an iphone for testing now, I'll test tonight. -
wrote on 26 Nov 2015, 21:49 last edited by
I tried without GCM service or GoogleService-Info.plist, but i haven't good results.
Then I came back to GoogleService-Info.plist loading problem.
Before I got this error :
Could not locate configuration file: 'GoogleService-Info.plist'.
But now, I have a better error :
The configuration file is not a dictionary: 'GoogleService-Info.plist'.
It looks better, isn't it ? :D .. but it still doesn't workThere is the fix in .pro file :
GInfo.files = ios/GoogleService-Info.plist GInfo.path = GoogleService-Info.plist QMAKE_BUNDLE_DATA += GInfo
-
wrote on 26 Nov 2015, 22:06 last edited by Leonardo
I don't get your code. I can compile successfully without GCM service. Here's a simplified version of my code:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { GGLInstanceIDConfig* idConfig = [GGLInstanceIDConfig defaultConfig]; idConfig.delegate = self; [[GGLInstanceID sharedInstance] startWithConfig:idConfig]; //==================================== if([application respondsToSelector:@selector(registerForRemoteNotifications)]){ [application registerForRemoteNotifications]; }else{ [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert]; } return YES; } -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { GGLInstanceID* idInstance = [GGLInstanceID sharedInstance]; [idInstance tokenWithAuthorizedEntity:@"123456789" scope:kGGLInstanceIDScopeGCM options:@{kGGLInstanceIDRegisterAPNSOption : deviceToken, kGGLInstanceIDAPNSServerTypeSandboxOption : @0} handler:^(NSString *token, NSError *error) { if(token != nil){ // } }]; }
-
wrote on 27 Nov 2015, 11:34 last edited by Vi67
Thx to share your code.
It's simpler than the Google sample.I'm just wondering what is the difference between putting startWithConfig in didFinishLaunchingWithOptions as you did, or put it in didRegisterForRemoteNotificationsWithDeviceToken as it's done in Google sample ?
I guess it's working, I just have this error, because I'm working on simulator :
Registration for remote notification failed with error: REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTIONI wait the device to make the final test.
-
wrote on 1 Dec 2015, 00:10 last edited by
Hello Leonardo,
Now GCM service is working fine for 2 ouf of 3 cases :
-
When the app is active -> OK
-
When the app is in background, then I click on the notif popup (in IOS UI), then the app comes back -> OK
-
But for the last case, there is a bug :
The app is closed. Then a notif popup is comming (in IOS UI), but when I click on it -> The app isn't shown back. The phone is almost blocked. It looks like the app is running in background but with a blackscreen. I don't even know how to have a log trace, because the app was previously closed manually.
I hope you can help me again. Any way, I'm reaching the end through your help.
-
1/25