{"id":15970,"date":"2015-02-09T09:57:09","date_gmt":"2015-02-09T08:57:09","guid":{"rendered":"http:\/\/puship.com\/?page_id=15970"},"modified":"2015-02-17T13:27:16","modified_gmt":"2015-02-17T12:27:16","slug":"ios","status":"publish","type":"page","link":"https:\/\/www.puship.com\/it\/documentazione\/metodi-deprecati\/ios\/","title":{"rendered":"iOS"},"content":{"rendered":"<ol>\n<li>Scarica il plugin phonegap per iOS da <a href=\"http:\/\/www.puship.com\/it\/documentazione\/phonegap-ios-plugin\/\" target=\"_blank\">questo link<\/a> (La versione di iOS minima supportata \u00e8 la 4.2).<\/li>\n<li>Fai un Drag and drop dal Finder della cartella <em>PushNotification<\/em> alla cartella <em>Plugins<\/em> su XCode, usando &#8220;Create groups for any added folders&#8221; and spuntando &#8220;Copy items if needed&#8221;.<\/li>\n<li>Aggiungi un nuovo elemento <i>plugin<\/i> nel file <em>config.xml<\/em> come specificato di seguito:\n<ol>\n<pre class=\"wp-code-highlight prettyprint\"><plugin name=\"PushNotification\" value=\"PushNotification\" \/><\/pre>\n<\/ol>\n<\/li>\n<li>Modifica la classe AppDelegate.h aggiungendo la seguente riga:\n<ol>\n<pre class=\"wp-code-highlight prettyprint\">#import \"PushNotification.h\"<\/pre>\n<\/ol>\n<\/li>\n<li>Modifica la classe AppDelegate.m aggiungendo questa porzione di codice appena prima del tag <i>@end<\/i>:\n<ol>\n<pre class=\"wp-code-highlight prettyprint\">\/* ... *\/\r\n\r\n\/* START BLOCK *\/\r\n\r\n#pragma PushNotification delegation\r\n\r\n- (void)application:(UIApplication*)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken\r\n{\r\n    PushNotification* pushHandler = [self.viewController getCommandInstance:@\"PushNotification\"];\r\n    [pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];\r\n}\r\n\r\n- (void)application:(UIApplication*)app didFailToRegisterForRemoteNotificationsWithError:(NSError*)error\r\n{\r\n    PushNotification* pushHandler = [self.viewController getCommandInstance:@\"PushNotification\"];\r\n    [pushHandler didFailToRegisterForRemoteNotificationsWithError:error];\r\n}\r\n\r\n- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo\r\n{\r\n    PushNotification* pushHandler = [self.viewController getCommandInstance:@\"PushNotification\"];\r\n    NSMutableDictionary* mutableUserInfo = [userInfo mutableCopy];\r\n\r\n    \/\/ Get application state for iOS4.x+ devices, otherwise assume active\r\n    UIApplicationState appState = UIApplicationStateActive;\r\n    if ([application respondsToSelector:@selector(applicationState)]) {\r\n        appState = application.applicationState;\r\n    }\r\n\r\n    [mutableUserInfo setValue:@\"0\" forKey:@\"applicationLaunchNotification\"];\r\n    if (appState == UIApplicationStateActive) {\r\n        [mutableUserInfo setValue:@\"1\" forKey:@\"applicationStateActive\"];\r\n        [pushHandler didReceiveRemoteNotification:mutableUserInfo];\r\n    } else {\r\n        [mutableUserInfo setValue:@\"0\" forKey:@\"applicationStateActive\"];\r\n        [mutableUserInfo setValue:[NSNumber numberWithDouble: [[NSDate date] timeIntervalSince1970]] forKey:@\"timestamp\"];\r\n        [pushHandler.pendingNotifications addObject:mutableUserInfo];\r\n    }\r\n}\r\n\r\n\/* STOP BLOCK *\/\r\n\r\n@end<\/pre>\n<\/ol>\n<\/li>\n<li>Aggiungi anche la seguente porzione di codice dentro il metodo <i>didFinishLaunchingWithOptions<\/i>, prima del <i>return YES<\/i>:\n<ol>\n<pre class=\"wp-code-highlight prettyprint\">\r\n[self.window addSubview:self.viewController.view];\r\n[self.window makeKeyAndVisible];\r\n\r\n\/* START BLOCK *\/\r\n\r\n\/\/ PushNotification - Handle launch from a push notification\r\nNSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];\r\nif(userInfo) {\r\n    PushNotification *pushHandler = [self.viewController getCommandInstance:@\"PushNotification\"];\r\n    NSMutableDictionary* mutableUserInfo = [userInfo mutableCopy];\r\n    [mutableUserInfo setValue:@\"1\" forKey:@\"applicationLaunchNotification\"];\r\n    [mutableUserInfo setValue:@\"0\" forKey:@\"applicationStateActive\"];\r\n    [pushHandler.pendingNotifications addObject:mutableUserInfo];\r\n}\r\n\r\n\/* STOP BLOCK *\/\r\n\r\nreturn YES;\r\n<\/pre>\n<\/ol>\n<\/li>\n<li>Aggiungi lo script <em>PushipNotification.js<\/em> alla tua cartella <em>assets\/www<\/em> e includilo nel file <em>index.html<\/em>.<\/li>\n<li>Aggiungi il codice seguente nel metodo <em>OnDeviceReady<\/em>:\n<ol>\n<pre class=\"wp-code-highlight prettyprint\">Puship.PushipAppId = puship_id; \/\/ un esempio di puship_id potrebbe essere: \"h1mCVGaP9dtGnwG\"\r\n\r\nPuship.APNS.Register(\r\n{\r\n    successCallback: function (pushipresult){\r\n        navigator.notification.alert(\"device registered with DeviceId:\" + pushipresult.DeviceId);\r\n    },\r\n    failCallback: function (pushipresult){\r\n        navigator.notification.alert(\"error during registration: \"+ JSON.stringify(pushipresult));\r\n    }\r\n});<\/pre>\n<\/ol>\n<\/li>\n<\/ol>\n<p>Si, questo \u00e8 tutto!<br \/>\nPuoi ora connetterti al <a href=\"http:\/\/www.puship.com\/it\/membri\/\">Puship Manager<\/a> e inviare notifiche push ai tuoi device!<\/p>\n<p>Per qualunque problema con la configurazione puoi scaricare l&#8217;esempio qui sotto<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><a  itemprop=\"url\" href=\"http:\/\/www.puship.com\/it\/documentazione\/esempio-phonegap-per-ios\/\" target=\"_self\"  class=\"qbutton  default\" style=\"\">Esempio iOS Completo<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Per poter invece aggiungere tags, gestire la geolocalizzazione e tutto ci\u00f2 che riguarda il resto delle api puship visita la documentazione comune per tutte le piattaforme:<\/p>\n<p style=\"text-align: center;\"><a  itemprop=\"url\" href=\"http:\/\/www.puship.com\/it\/documentazione\/guida-common\/\" target=\"_self\"  class=\"qbutton  default\" style=\"\">Documentazione sulla libreria Common<\/a><\/p>\n<p>&nbsp;\n\t\t<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Scarica il plugin phonegap per iOS da questo link (La versione di iOS minima supportata \u00e8 la 4.2). Fai un Drag and drop dal Finder della cartella PushNotification alla cartella Plugins su XCode, usando &#8220;Create groups for any added folders&#8221; and spuntando &#8220;Copy items if&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":15965,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.puship.com\/it\/wp-json\/wp\/v2\/pages\/15970\/"}],"collection":[{"href":"https:\/\/www.puship.com\/it\/wp-json\/wp\/v2\/pages\/"}],"about":[{"href":"https:\/\/www.puship.com\/it\/wp-json\/wp\/v2\/types\/page\/"}],"author":[{"embeddable":true,"href":"https:\/\/www.puship.com\/it\/wp-json\/wp\/v2\/users\/1\/"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puship.com\/it\/wp-json\/wp\/v2\/comments\/?post=15970"}],"version-history":[{"count":5,"href":"https:\/\/www.puship.com\/it\/wp-json\/wp\/v2\/pages\/15970\/revisions\/"}],"predecessor-version":[{"id":16737,"href":"https:\/\/www.puship.com\/it\/wp-json\/wp\/v2\/pages\/15970\/revisions\/16737\/"}],"up":[{"embeddable":true,"href":"https:\/\/www.puship.com\/it\/wp-json\/wp\/v2\/pages\/15965\/"}],"wp:attachment":[{"href":"https:\/\/www.puship.com\/it\/wp-json\/wp\/v2\/media\/?parent=15970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}