你可以帮我检查一下配置过程中是否遗漏了什么,因为一旦应用程序被杀,我就无法收到通知。如果应用程序只是最小化,则会显示呼叫通知,但对于即时消息,手机只会弹出一个流行音,但没有显示任何通知。 使用C2Call如何在AppDelegate子类中调用以下方法。
[super application:didRegisterForRemoteNotificationsWithDeviceToken];
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
//[self registerDeviceToken:devToken];
// Get Bundle Info for Remote Registration (handy if you have more than one app)
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
// Check what Notifications the user has turned on. We registered for all three, but they may have manually disabled some or all of them.
//
NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
// Set the defaults to disabled unless we find otherwise...
NSString *pushBadge = @"disabled";
NSString *pushAlert = @"disabled";
NSString *pushSound = @"disabled";
if(rntypes == UIRemoteNotificationTypeBadge){
pushBadge = @"enabled";
}
else if(rntypes == UIRemoteNotificationTypeAlert){
pushAlert = @"enabled";
}
else if(rntypes == UIRemoteNotificationTypeSound){
pushSound = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)){ pushBadge = @"enabled";
pushAlert = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)){ pushBadge = @"enabled";
pushSound = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){ pushAlert = @"enabled";
pushSound = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){
pushBadge = @"enabled";
pushAlert = @"enabled";
pushSound = @"enabled";
}
// Get the users Device Model, Display Name, Unique ID, Token & Version Number
UIDevice *dev = [UIDevice currentDevice];
// NSString *deviceUuid=dev.uniqueIdentifier;
NSString *deviceUuid = [[dev identifierForVendor] UUIDString];
NSString *deviceName = dev.name;
NSString *deviceModel = dev.model;
NSString *deviceSystemVersion = dev.systemVersion;
//Prepare the Device Token for Registration (remove spaces and < >)
NSString *deviceToken = [[[[devToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""] stringByReplacingOccurrencesOfString:@">" withString:@""] stringByReplacingOccurrencesOfString: @" " withString: @""];
NSString *urlString = [@"/pushservice/apns/user/register"stringByAppendingString:@"r=user/register"];
NSLog(@"devicetoken length: %i", [deviceToken length]);
urlString = [urlString stringByAppendingString:@"&appname="];
urlString = [urlString stringByAppendingString:appName];
urlString = [urlString stringByAppendingString:@"&appversion="];
urlString = [urlString stringByAppendingString:appVersion];
urlString = [urlString stringByAppendingString:@"&deviceuid="];
urlString = [urlString stringByAppendingString:deviceUuid];
urlString = [urlString stringByAppendingString:@"&devicetoken="];
urlString = [urlString stringByAppendingString:deviceToken];
urlString = [urlString stringByAppendingString:@"&devicename="];
urlString = [urlString stringByAppendingString:deviceName];
urlString = [urlString stringByAppendingString:@"&devicemodel="];
urlString = [urlString stringByAppendingString:deviceModel];
urlString = [urlString stringByAppendingString:@"&deviceversion="];
urlString = [urlString stringByAppendingString:deviceSystemVersion];
urlString = [urlString stringByAppendingString:@"&pushbadge="];
urlString = [urlString stringByAppendingString:pushBadge];
urlString = [urlString stringByAppendingString:@"&pushalert="];
urlString = [urlString stringByAppendingString:pushAlert];
urlString = [urlString stringByAppendingString:@"&pushsound="];
urlString = [urlString stringByAppendingString:pushSound];
NSUserDefaults *def=[NSUserDefaults standardUserDefaults];
[def setObject:deviceToken forKey:@"token"];
[def synchronize];
//[super application:didRegisterForRemoteNotificationsWithDeviceToken];
}
答案 0 :(得分:0)
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
[super application:didRegisterForRemoteNotificationsWithDeviceToken];
//[self registerDeviceToken:devToken];
// Get Bundle Info for Remote Registration (handy if you have more than one app)
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
// Check what Notifications the user has turned on. We registered for all three, but they may have manually disabled some or all of them.
//
NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
// Set the defaults to disabled unless we find otherwise...
NSString *pushBadge = @"disabled";
NSString *pushAlert = @"disabled";
NSString *pushSound = @"disabled";
if(rntypes == UIRemoteNotificationTypeBadge){
pushBadge = @"enabled";
}
else if(rntypes == UIRemoteNotificationTypeAlert){
pushAlert = @"enabled";
}
else if(rntypes == UIRemoteNotificationTypeSound){
pushSound = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)){ pushBadge = @"enabled";
pushAlert = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)){ pushBadge = @"enabled";
pushSound = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){ pushAlert = @"enabled";
pushSound = @"enabled";
}
else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){
pushBadge = @"enabled";
pushAlert = @"enabled";
pushSound = @"enabled";
}
// Get the users Device Model, Display Name, Unique ID, Token & Version Number
UIDevice *dev = [UIDevice currentDevice];
// NSString *deviceUuid=dev.uniqueIdentifier;
NSString *deviceUuid = [[dev identifierForVendor] UUIDString];
NSString *deviceName = dev.name;
NSString *deviceModel = dev.model;
NSString *deviceSystemVersion = dev.systemVersion;
//Prepare the Device Token for Registration (remove spaces and < >)
NSString *deviceToken = [[[[devToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""] stringByReplacingOccurrencesOfString:@">" withString:@""] stringByReplacingOccurrencesOfString: @" " withString: @""];
NSString *urlString = [@"/pushservice/apns/user/register"stringByAppendingString:@"r=user/register"];
NSLog(@"devicetoken length: %i", [deviceToken length]);
urlString = [urlString stringByAppendingString:@"&appname="];
urlString = [urlString stringByAppendingString:appName];
urlString = [urlString stringByAppendingString:@"&appversion="];
urlString = [urlString stringByAppendingString:appVersion];
urlString = [urlString stringByAppendingString:@"&deviceuid="];
urlString = [urlString stringByAppendingString:deviceUuid];
urlString = [urlString stringByAppendingString:@"&devicetoken="];
urlString = [urlString stringByAppendingString:deviceToken];
urlString = [urlString stringByAppendingString:@"&devicename="];
urlString = [urlString stringByAppendingString:deviceName];
urlString = [urlString stringByAppendingString:@"&devicemodel="];
urlString = [urlString stringByAppendingString:deviceModel];
urlString = [urlString stringByAppendingString:@"&deviceversion="];
urlString = [urlString stringByAppendingString:deviceSystemVersion];
urlString = [urlString stringByAppendingString:@"&pushbadge="];
urlString = [urlString stringByAppendingString:pushBadge];
urlString = [urlString stringByAppendingString:@"&pushalert="];
urlString = [urlString stringByAppendingString:pushAlert];
urlString = [urlString stringByAppendingString:@"&pushsound="];
urlString = [urlString stringByAppendingString:pushSound];
NSUserDefaults *def=[NSUserDefaults standardUserDefaults];
[def setObject:deviceToken forKey:@"token"];
[def synchronize];
}
答案 1 :(得分:0)
使用以下代码: -
(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken { // [self registerDeviceToken:devToken]; //获取远程注册的捆绑信息(如果您有多个应用程序,则很方便) NSString * appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@&#34; CFBundleDisplayName&#34;]; NSString * appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@&#34; CFBundleVersion&#34;];
//检查用户已启用的通知。我们注册了所有这三个,但他们可能已经手动禁用了部分或全部。 //
NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
//将默认值设置为禁用,除非我们另外发现......
NSString * pushBadge = @&#34;禁用&#34 ;; NSString * pushAlert = @&#34;禁用&#34 ;; NSString * pushSound = @&#34;禁用&#34 ;;
if(rntypes == UIRemoteNotificationTypeBadge){ pushBadge = @&#34;启用&#34 ;; } else if(rntypes == UIRemoteNotificationTypeAlert){ pushAlert = @&#34;启用&#34 ;; } else if(rntypes == UIRemoteNotificationTypeSound){ pushSound = @&#34;启用&#34 ;; } else if(rntypes ==(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)){pushBadge = @&#34; enabled&#34 ;; pushAlert = @&#34;启用&#34 ;; } else if(rntypes ==(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)){pushBadge = @&#34; enabled&#34 ;; pushSound = @&#34;启用&#34 ;; } else if(rntypes ==(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){pushAlert = @&#34; enabled&#34 ;; pushSound = @&#34;启用&#34 ;; } else if(rntypes ==(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){ pushBadge = @&#34;启用&#34 ;; pushAlert = @&#34;启用&#34 ;; pushSound = @&#34;启用&#34 ;; }
//获取用户设备型号,显示名称,唯一ID,令牌和版本号 UIDevice * dev = [UIDevice currentDevice]; // NSString * deviceUuid = dev.uniqueIdentifier; NSString * deviceUuid = [[dev identifierForVendor] UUIDString]; NSString * deviceName = dev.name; NSString * deviceModel = dev.model; NSString * deviceSystemVersion = dev.systemVersion;
//为注册准备设备令牌(删除空格和&lt;&gt;) NSString * deviceToken = [[[[devToken description] stringByReplacingOccurrencesOfString:@&#34;&lt;&#34; withString:@&#34;&#34;] stringByReplacingOccurrencesOfString:@&#34;&gt;&#34; withString:@&#34;&#34;] stringByReplacingOccurrencesOfString:@&#34; &#34; withString:@&#34;&#34;]; NSString * urlString = [@&#34; / pushservice / apns / user / register&#34; stringByAppendingString:@&#34; r = user / register&#34;]; NSLog(@&#34; devicetoken长度:%i&#34;,[deviceToken长度]); urlString = [urlString stringByAppendingString:@&#34;&amp; appname =&#34;]; urlString = [urlString stringByAppendingString:appName]; urlString = [urlString stringByAppendingString:@&#34;&amp; appversion =&#34;]; urlString = [urlString stringByAppendingString:appVersion]; urlString = [urlString stringByAppendingString:@&#34;&amp; deviceuid =&#34;]; urlString = [urlString stringByAppendingString:deviceUuid]; urlString = [urlString stringByAppendingString:@&#34;&amp; devicetoken =&#34;]; urlString = [urlString stringByAppendingString:deviceToken]; urlString = [urlString stringByAppendingString:@&#34;&amp; devicename =&#34;]; urlString = [urlString stringByAppendingString:deviceName]; urlString = [urlString stringByAppendingString:@&#34;&amp; devicemodel =&#34;]; urlString = [urlString stringByAppendingString:deviceModel]; urlString = [urlString stringByAppendingString:@&#34;&amp; deviceversion =&#34;]; urlString = [urlString stringByAppendingString:deviceSystemVersion]; urlString = [urlString stringByAppendingString:@&#34;&amp; pushbadge =&#34;]; urlString = [urlString stringByAppendingString:pushBadge]; urlString = [urlString stringByAppendingString:@&#34;&amp; pushalert =&#34;]; urlString = [urlString stringByAppendingString:pushAlert]; urlString = [urlString stringByAppendingString:@&#34;&amp; pushsound =&#34;]; urlString = [urlString stringByAppendingString:pushSound]; strGlobalDeviceToken = deviceToken; NSLog(@&#34; deviceToken%@&#34;,strGlobalDeviceToken); NSUserDefaults * def = [NSUserDefaults standardUserDefaults]; [def setObject:deviceToken forKey:@&#34; token&#34;]; [def synchronize];
[超级应用程序:application didRegisterForRemoteNotificationsWithDeviceToken:devToken];
}